cleanup
This commit is contained in:
parent
295982f6e6
commit
df0b6b6ff0
3 changed files with 18 additions and 17 deletions
|
@ -2,7 +2,6 @@ use crossterm::{
|
||||||
cursor::{self, MoveTo},
|
cursor::{self, MoveTo},
|
||||||
event::{self, Event, KeyCode, KeyEvent, KeyModifiers},
|
event::{self, Event, KeyCode, KeyEvent, KeyModifiers},
|
||||||
queue,
|
queue,
|
||||||
style::{Color, Colors, ResetColor, SetColors},
|
|
||||||
terminal::{self, Clear, ClearType},
|
terminal::{self, Clear, ClearType},
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -15,7 +14,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::clipboard::Clipboard;
|
use crate::clipboard::Clipboard;
|
||||||
use crate::util::read_line;
|
use crate::util::{color_highlight, color_reset, read_line};
|
||||||
|
|
||||||
const TAB_SIZE: usize = 4;
|
const TAB_SIZE: usize = 4;
|
||||||
|
|
||||||
|
@ -186,7 +185,7 @@ impl Editor {
|
||||||
for (i, char) in text.char_indices() {
|
for (i, char) in text.char_indices() {
|
||||||
let char_i = line.start + i;
|
let char_i = line.start + i;
|
||||||
if char_i >= selection.start && char_i <= selection.end && !in_selection {
|
if char_i >= selection.start && char_i <= selection.end && !in_selection {
|
||||||
color_selection();
|
color_highlight();
|
||||||
in_selection = true;
|
in_selection = true;
|
||||||
} else if char_i > selection.end && in_selection {
|
} else if char_i > selection.end && in_selection {
|
||||||
color_reset();
|
color_reset();
|
||||||
|
@ -459,11 +458,3 @@ impl Editor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn color_selection() {
|
|
||||||
queue!(stdout(), SetColors(Colors::new(Color::Black, Color::White))).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn color_reset() {
|
|
||||||
queue!(stdout(), ResetColor).unwrap();
|
|
||||||
}
|
|
||||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -2,7 +2,6 @@ use crossterm::{
|
||||||
cursor::{self, MoveTo},
|
cursor::{self, MoveTo},
|
||||||
event::{self, Event, KeyCode, KeyModifiers},
|
event::{self, Event, KeyCode, KeyModifiers},
|
||||||
execute, queue,
|
execute, queue,
|
||||||
style::{Color, Colors, ResetColor, SetColors},
|
|
||||||
terminal::{
|
terminal::{
|
||||||
self, disable_raw_mode, enable_raw_mode, Clear, ClearType, EnterAlternateScreen,
|
self, disable_raw_mode, enable_raw_mode, Clear, ClearType, EnterAlternateScreen,
|
||||||
LeaveAlternateScreen,
|
LeaveAlternateScreen,
|
||||||
|
@ -18,6 +17,7 @@ use std::{
|
||||||
mod clipboard;
|
mod clipboard;
|
||||||
mod editor;
|
mod editor;
|
||||||
mod util;
|
mod util;
|
||||||
|
use crate::util::{color_highlight, color_reset};
|
||||||
use clipboard::Clipboard;
|
use clipboard::Clipboard;
|
||||||
use editor::Editor;
|
use editor::Editor;
|
||||||
|
|
||||||
|
@ -97,11 +97,11 @@ impl Navigator {
|
||||||
|
|
||||||
for (index, editor) in self.editors.iter().enumerate() {
|
for (index, editor) in self.editors.iter().enumerate() {
|
||||||
if index == self.selected {
|
if index == self.selected {
|
||||||
queue!(stdout(), SetColors(Colors::new(Color::Black, Color::White))).unwrap();
|
color_highlight();
|
||||||
}
|
}
|
||||||
queue!(stdout(), MoveTo(1, index as u16 + 1)).unwrap();
|
queue!(stdout(), MoveTo(1, index as u16 + 1)).unwrap();
|
||||||
print!("{}", editor.title());
|
print!("{}", editor.title());
|
||||||
queue!(stdout(), ResetColor).unwrap();
|
color_reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
let offset = self.editors.len() as u16 + 2;
|
let offset = self.editors.len() as u16 + 2;
|
||||||
|
@ -114,7 +114,7 @@ impl Navigator {
|
||||||
|
|
||||||
for (index, path) in self.files[visible_rows].iter().enumerate() {
|
for (index, path) in self.files[visible_rows].iter().enumerate() {
|
||||||
if index + self.scroll == self.selected.wrapping_sub(self.editors.len()) {
|
if index + self.scroll == self.selected.wrapping_sub(self.editors.len()) {
|
||||||
queue!(stdout(), SetColors(Colors::new(Color::Black, Color::White))).unwrap();
|
color_highlight();
|
||||||
}
|
}
|
||||||
queue!(stdout(), MoveTo(1, index as u16 + 1 + offset)).unwrap();
|
queue!(stdout(), MoveTo(1, index as u16 + 1 + offset)).unwrap();
|
||||||
if let Some(name) = path.file_name() {
|
if let Some(name) = path.file_name() {
|
||||||
|
@ -125,7 +125,7 @@ impl Navigator {
|
||||||
if path.is_dir() {
|
if path.is_dir() {
|
||||||
print!("/");
|
print!("/");
|
||||||
}
|
}
|
||||||
queue!(stdout(), ResetColor).unwrap();
|
color_reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(text) = &self.message {
|
if let Some(text) = &self.message {
|
||||||
|
|
12
src/util.rs
12
src/util.rs
|
@ -1,7 +1,9 @@
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
cursor,
|
cursor,
|
||||||
event::{self, Event, KeyCode},
|
event::{self, Event, KeyCode},
|
||||||
queue, terminal,
|
queue,
|
||||||
|
style::{Color, Colors, ResetColor, SetColors},
|
||||||
|
terminal,
|
||||||
};
|
};
|
||||||
use std::io::{stdout, Write};
|
use std::io::{stdout, Write};
|
||||||
|
|
||||||
|
@ -37,3 +39,11 @@ pub fn read_line(prompt: &str) -> Option<String> {
|
||||||
}
|
}
|
||||||
Some(response.trim().into())
|
Some(response.trim().into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn color_highlight() {
|
||||||
|
queue!(stdout(), SetColors(Colors::new(Color::Black, Color::White))).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn color_reset() {
|
||||||
|
queue!(stdout(), ResetColor).unwrap();
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue