diff options
| author | Roee Shapira <35409124+5c077m4n@users.noreply.github.com> | 2020-11-19 12:15:59 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-19 11:15:59 +0100 |
| commit | 5ddf95a16c8d1c9632ba6cef56f55fcf8bf9e4ea (patch) | |
| tree | 94a00125fb99f7cf0953e20052eb000647c9f212 /src/main.rs | |
| parent | fix(ux): disable move focus when in full screen (#49) (diff) | |
| download | sl0ppij-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/main.rs')
| -rw-r--r-- | src/main.rs | 38 |
1 files changed, 11 insertions, 27 deletions
diff --git a/src/main.rs b/src/main.rs index 315e8eb1..d331451c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,12 @@ -#[cfg(test)] -mod tests; - mod boundaries; mod layout; mod os_input_output; mod pty_bus; mod screen; mod terminal_pane; +#[cfg(test)] +mod tests; +mod utils; use std::io::{Read, Write}; use std::os::unix::net::UnixStream; @@ -22,6 +22,7 @@ use crate::layout::Layout; use crate::os_input_output::{get_os_input, OsApi}; use crate::pty_bus::{PtyBus, PtyInstruction, VteEvent}; use crate::screen::{Screen, ScreenInstruction}; +use crate::utils::{consts::MOSAIC_TMP_FOLDER, logging::*}; #[derive(Serialize, Deserialize, Debug)] enum ApiCommand { @@ -53,46 +54,28 @@ pub struct Opt { debug: bool, } -fn _debug_log_to_file(message: String) { - use std::fs::OpenOptions; - use std::io::prelude::*; - let mut file = OpenOptions::new() - .append(true) - .create(true) - .open("/tmp/mosaic-log.txt") - .unwrap(); - file.write_all(message.as_bytes()).unwrap(); - file.write_all("\n".as_bytes()).unwrap(); -} - -fn delete_log_files() -> std::io::Result<()> { - std::fs::remove_dir_all("/tmp/mosaic-logs").ok(); - std::fs::create_dir_all("/tmp/mosaic-logs").ok(); - Ok(()) -} - pub fn main() { let opts = Opt::from_args(); if opts.split.is_some() { match opts.split { Some('h') => { - let mut stream = UnixStream::connect("/tmp/mosaic").unwrap(); + let mut stream = UnixStream::connect(MOSAIC_TMP_FOLDER).unwrap(); let api_command = bincode::serialize(&ApiCommand::SplitHorizontally).unwrap(); stream.write_all(&api_command).unwrap(); } Some('v') => { - let mut stream = UnixStream::connect("/tmp/mosaic").unwrap(); + let mut stream = UnixStream::connect(MOSAIC_TMP_FOLDER).unwrap(); let api_command = bincode::serialize(&ApiCommand::SplitVertically).unwrap(); stream.write_all(&api_command).unwrap(); } _ => {} }; } else if opts.move_focus { - let mut stream = UnixStream::connect("/tmp/mosaic").unwrap(); + let mut stream = UnixStream::connect(MOSAIC_TMP_FOLDER).unwrap(); let api_command = bincode::serialize(&ApiCommand::MoveFocus).unwrap(); stream.write_all(&api_command).unwrap(); } else if opts.open_file.is_some() { - let mut stream = UnixStream::connect("/tmp/mosaic").unwrap(); + let mut stream = UnixStream::connect(MOSAIC_TMP_FOLDER).unwrap(); let file_to_open = opts.open_file.unwrap(); let api_command = bincode::serialize(&ApiCommand::OpenFile(file_to_open)).unwrap(); stream.write_all(&api_command).unwrap(); @@ -109,7 +92,8 @@ pub enum AppInstruction { pub fn start(mut os_input: Box<dyn OsApi>, opts: Opt) { let mut active_threads = vec![]; - delete_log_files().unwrap(); + delete_log_dir().unwrap(); + delete_log_file().unwrap(); let full_screen_ws = os_input.get_terminal_size_using_fd(0); os_input.into_raw_mode(0); @@ -335,7 +319,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: Opt) { let mut buffer = [0; 10]; // TODO: more accurately stdin.read(&mut buffer).expect("failed to read stdin"); // uncomment this to print the entered character to a log file (/tmp/mosaic-log.txt) for debugging - // _debug_log_to_file(format!("buffer {:?}", buffer)); + //crate::utils::logging::debug_log_to_file(format!("buffer {:?}", buffer)); match buffer { [10, 0, 0, 0, 0, 0, 0, 0, 0, 0] => { // ctrl-j |
