aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorRoee Shapira <35409124+5c077m4n@users.noreply.github.com>2020-11-19 12:15:59 +0200
committerGitHub <noreply@github.com>2020-11-19 11:15:59 +0100
commit5ddf95a16c8d1c9632ba6cef56f55fcf8bf9e4ea (patch)
tree94a00125fb99f7cf0953e20052eb000647c9f212 /src/utils
parentfix(ux): disable move focus when in full screen (#49) (diff)
downloadsl0ppij-5ddf95a16c8d1c9632ba6cef56f55fcf8bf9e4ea.tar.gz
sl0ppij-5ddf95a16c8d1c9632ba6cef56f55fcf8bf9e4ea.tar.xz
sl0ppij-5ddf95a16c8d1c9632ba6cef56f55fcf8bf9e4ea.zip
fix(compatibility): some fixes for htop (#53)
* Moved all log to file functions to one module. * Moved logging to file function to utils module. * Housekeeping. * Housekeeping. * Started investigation into htop CSIs. * Used better function for scrolling. * Minor cleanup. * Cleanup and start of scroll region rotation. * Implemented scroll region rotation. * Improved performace. * New SCI found. * Typo. * Typo. * Removed logging function. * Added scroll rotation functions. * Typo. * Moved all logging function to one module. * Attempt at making htop work. * Reverted unneeded changes. * Improved log file name creation. * Ran rust fmt. * PR review edits. * PR review edits. * Used mark_for_rerender function. * Removed _ prefix from logging functions.
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/consts.rs3
-rw-r--r--src/utils/logging.rs58
-rw-r--r--src/utils/mod.rs2
3 files changed, 63 insertions, 0 deletions
diff --git a/src/utils/consts.rs b/src/utils/consts.rs
new file mode 100644
index 00000000..5eb96c67
--- /dev/null
+++ b/src/utils/consts.rs
@@ -0,0 +1,3 @@
+pub const MOSAIC_TMP_LOG_FILE: &str = "/tmp/mosaic-log.txt";
+pub const MOSAIC_TMP_LOG_DIR: &str = "/tmp/mosaic-log";
+pub const MOSAIC_TMP_FOLDER: &str = "/tmp/mosaic";
diff --git a/src/utils/logging.rs b/src/utils/logging.rs
new file mode 100644
index 00000000..77e924a9
--- /dev/null
+++ b/src/utils/logging.rs
@@ -0,0 +1,58 @@
+use std::{
+ fs,
+ io::{self, prelude::*},
+ os::unix::io::RawFd,
+ path::PathBuf,
+};
+
+use crate::utils::consts::{MOSAIC_TMP_LOG_DIR, MOSAIC_TMP_LOG_FILE};
+
+pub fn debug_log_to_file(message: String) -> io::Result<()> {
+ let mut file = fs::OpenOptions::new()
+ .append(true)
+ .create(true)
+ .open(MOSAIC_TMP_LOG_FILE)?;
+ file.write_all(message.as_bytes())?;
+ file.write_all("\n".as_bytes())?;
+
+ Ok(())
+}
+
+pub fn debug_log_to_file_pid_0(message: String, pid: RawFd) -> io::Result<()> {
+ if pid == 0 {
+ debug_log_to_file(message)?;
+ }
+
+ Ok(())
+}
+
+pub fn delete_log_file() -> io::Result<()> {
+ if fs::metadata(MOSAIC_TMP_LOG_FILE).is_ok() {
+ fs::remove_file(MOSAIC_TMP_LOG_FILE)?;
+ }
+
+ Ok(())
+}
+
+pub fn delete_log_dir() -> io::Result<()> {
+ if fs::metadata(MOSAIC_TMP_LOG_DIR).is_ok() {
+ fs::remove_dir_all(MOSAIC_TMP_LOG_DIR)?;
+ }
+ fs::create_dir_all(MOSAIC_TMP_LOG_DIR)?;
+
+ Ok(())
+}
+
+pub fn debug_to_file(message: u8, pid: RawFd) -> io::Result<()> {
+ let mut path = PathBuf::new();
+ path.push(MOSAIC_TMP_LOG_DIR);
+ path.push(format!("mosaic-{}.log", pid.to_string()));
+
+ let mut file = fs::OpenOptions::new()
+ .append(true)
+ .create(true)
+ .open(path)?;
+ file.write_all(&[message])?;
+
+ Ok(())
+}
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
new file mode 100644
index 00000000..140eec18
--- /dev/null
+++ b/src/utils/mod.rs
@@ -0,0 +1,2 @@
+pub mod consts;
+pub mod logging;