Skip to content

Commit

Permalink
Windows fix
Browse files Browse the repository at this point in the history
  • Loading branch information
angelcaru committed Feb 28, 2024
1 parent f18ba9a commit 5157a25
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn is_ident(ch: u8) -> bool {

pub fn split_words(mut code: &[u8]) -> Vec<Word> {
fn is_ch_usable(ch: u8) -> bool {
is_ident(ch) || is_quote(ch)
is_ident(ch) || is_quote(ch)
}

let mut words = Vec::new();
Expand Down
36 changes: 31 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ use crossterm::{
ExecutableCommand, QueueableCommand,
};
use std::{
cmp::Ordering, io::{Read, Write}, net::{IpAddr, SocketAddr, TcpListener}, num::NonZeroUsize, process::exit, str::FromStr, sync::mpsc::{self, Sender}, thread, time::Duration
cmp::Ordering,
io::{Read, Write},
net::{IpAddr, SocketAddr, TcpListener},
num::NonZeroUsize,
process::exit,
str::FromStr,
sync::mpsc::{self, Sender},
thread,
time::Duration,
};

use display::*;
Expand Down Expand Up @@ -516,7 +524,7 @@ impl Editor {
if let CursorState::Default = self.cursor.state {
y += 1;
}

self.buf.insert(y, row);
}
self.buf[y].extend_from_slice(&post);
Expand All @@ -540,6 +548,7 @@ impl Editor {
Event::Key(KeyEvent {
code: KeyCode::Char('q'),
modifiers: KeyModifiers::CONTROL,
kind: KeyEventKind::Press | KeyEventKind::Repeat,
..
}) => {
if self.unsaved_changes {
Expand All @@ -554,21 +563,25 @@ impl Editor {
Event::Key(KeyEvent {
code: KeyCode::Char('s'),
modifiers: KeyModifiers::CONTROL,
kind: KeyEventKind::Press | KeyEventKind::Repeat,
..
}) => self.save_file()?,
Event::Key(KeyEvent {
code: KeyCode::Char('c'),
modifiers: KeyModifiers::CONTROL,
kind: KeyEventKind::Press | KeyEventKind::Repeat,
..
}) => self.copy_text(),
Event::Key(KeyEvent {
code: KeyCode::Char('v'),
modifiers: KeyModifiers::CONTROL,
kind: KeyEventKind::Press | KeyEventKind::Repeat,
..
}) => self.paste_text(),
Event::Key(KeyEvent {
code: KeyCode::Char(ch),
modifiers: KeyModifiers::NONE | KeyModifiers::SHIFT,
kind: KeyEventKind::Press | KeyEventKind::Repeat,
..
}) => {
self.unsaved_changes = true;
Expand All @@ -584,6 +597,7 @@ impl Editor {
Event::Key(KeyEvent {
code: KeyCode::Enter,
modifiers: KeyModifiers::NONE,
kind: KeyEventKind::Press | KeyEventKind::Repeat,
..
}) => {
if let CursorState::StatusBar = self.cursor.state {
Expand Down Expand Up @@ -625,6 +639,7 @@ impl Editor {
Event::Key(KeyEvent {
code: KeyCode::Tab,
modifiers: KeyModifiers::NONE,
kind: KeyEventKind::Press | KeyEventKind::Repeat,
..
}) => {
for _ in 0..4 {
Expand All @@ -635,6 +650,7 @@ impl Editor {
// Ctrl+Backspace == Ctrl+H for some reason
code: KeyCode::Backspace | KeyCode::Char('h'),
modifiers,
kind: KeyEventKind::Press | KeyEventKind::Repeat,
..
}) if modifiers == KeyModifiers::NONE || modifiers == KeyModifiers::CONTROL => {
assert!(self.cursor.pos.1 < self.buf.len());
Expand All @@ -652,6 +668,7 @@ impl Editor {
Event::Key(KeyEvent {
code: KeyCode::Delete,
modifiers,
kind: KeyEventKind::Press | KeyEventKind::Repeat,
..
}) if modifiers == KeyModifiers::NONE || modifiers == KeyModifiers::CONTROL => {
assert!(self.cursor.pos.1 < self.buf.len());
Expand Down Expand Up @@ -688,6 +705,7 @@ impl Editor {
Event::Key(KeyEvent {
code: KeyCode::Left,
modifiers,
kind: KeyEventKind::Press | KeyEventKind::Repeat,
..
}) => {
self.update_selection(modifiers);
Expand All @@ -700,6 +718,7 @@ impl Editor {
Event::Key(KeyEvent {
code: KeyCode::Right,
modifiers,
kind: KeyEventKind::Press | KeyEventKind::Repeat,
..
}) => {
self.update_selection(modifiers);
Expand All @@ -712,6 +731,7 @@ impl Editor {
Event::Key(KeyEvent {
code: KeyCode::Up,
modifiers,
kind: KeyEventKind::Press | KeyEventKind::Repeat,
..
}) if modifiers == KeyModifiers::NONE || modifiers == KeyModifiers::SHIFT => {
self.update_selection(modifiers);
Expand All @@ -720,6 +740,7 @@ impl Editor {
Event::Key(KeyEvent {
code: KeyCode::Down,
modifiers,
kind: KeyEventKind::Press | KeyEventKind::Repeat,
..
}) if modifiers == KeyModifiers::NONE || modifiers == KeyModifiers::SHIFT => {
self.update_selection(modifiers);
Expand All @@ -728,6 +749,7 @@ impl Editor {
Event::Key(KeyEvent {
code: KeyCode::Home,
modifiers,
kind: KeyEventKind::Press | KeyEventKind::Repeat,
..
}) if modifiers == KeyModifiers::NONE || modifiers == KeyModifiers::SHIFT => {
self.update_selection(modifiers);
Expand All @@ -736,6 +758,7 @@ impl Editor {
Event::Key(KeyEvent {
code: KeyCode::End,
modifiers,
kind: KeyEventKind::Press | KeyEventKind::Repeat,
..
}) if modifiers == KeyModifiers::NONE || modifiers == KeyModifiers::SHIFT => {
self.update_selection(modifiers);
Expand All @@ -744,6 +767,7 @@ impl Editor {
Event::Key(KeyEvent {
code: KeyCode::Esc,
modifiers: KeyModifiers::NONE,
kind: KeyEventKind::Press | KeyEventKind::Repeat,
..
}) => {
self.set_status_prompt("Command: ".into(), PromptType::Command);
Expand Down Expand Up @@ -797,7 +821,7 @@ impl Editor {
let num = y + cy;

let num_str = lpad((num + 1).to_string(), 3);
let num_str = String::from(&num_str[num_str.len()-3..]);
let num_str = String::from(&num_str[num_str.len() - 3..]);

for x in 0..(UI_WIDTH - 1) {
let x = x as usize;
Expand Down Expand Up @@ -990,12 +1014,14 @@ fn main() -> Result<(), std::io::Error> {

terminal::enable_raw_mode()?;
editor.display.queue_clear()?;

editor.display.stdout.queue(PushKeyboardEnhancementFlags(
KeyboardEnhancementFlags::REPORT_EVENT_TYPES,
))?;

loop {
if poll(polling_rate)? {
editor.handle_event(read()?)?;
}
editor.render()?;
}
}

0 comments on commit 5157a25

Please sign in to comment.