From ea9e0e3ed85124a4f77eaf0225885e535ab04453 Mon Sep 17 00:00:00 2001 From: "Matheus T. dos Santos" Date: Fri, 15 Mar 2024 08:38:19 -0300 Subject: [PATCH 1/4] fix: fixes horizontal scroll bug --- src/command_bar.rs | 2 +- src/rich_string.rs | 49 +++++++++++++++++++++++++++++++++------------- src/text.rs | 8 +------- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/command_bar.rs b/src/command_bar.rs index c7392ab..b254b6f 100644 --- a/src/command_bar.rs +++ b/src/command_bar.rs @@ -92,7 +92,7 @@ impl CommandBar { match event { Some(Ok(event)) => match event { - Event::Mouse(mouse_evt) if mouse_evt.modifiers == KeyModifiers::CONTROL => { + Event::Mouse(mouse_evt) if mouse_evt.modifiers == KeyModifiers::SHIFT => { match mouse_evt.kind { MouseEventKind::ScrollUp => sender.send(HorizontalScroll(-1)).unwrap(), MouseEventKind::ScrollDown => sender.send(HorizontalScroll(1)).unwrap(), diff --git a/src/rich_string.rs b/src/rich_string.rs index 5e2e4e1..af172c6 100644 --- a/src/rich_string.rs +++ b/src/rich_string.rs @@ -4,6 +4,7 @@ use ratatui::style::{Color, Style}; use ratatui::text::Span; use std::collections::HashMap; +#[derive(Clone)] pub struct RichText { content: Vec, fg: Color, @@ -38,16 +39,34 @@ impl RichText { ) } - pub fn crop_prefix_len(&self, len: usize) -> Self { - Self { - content: if len >= self.content.len() { - vec![] - } else { - self.content[len..].to_vec() - }, - fg: self.fg, - bg: self.bg, - } + pub fn crop_rich_texts(rich_texts: &[RichText], cursor: usize) -> Vec { + rich_texts + .iter() + .fold((cursor, vec![]), |(mut cursor, mut acc), text| { + if cursor == 0 { + acc.push(text.clone().to_span()); + return (0, acc); + } + + match cursor { + x if x < text.content.len() => { + acc.push( + Self { + content: text.content[cursor..].to_vec(), + fg: text.fg, + bg: text.bg, + } + .to_span(), + ); + cursor = 0; + } + x if x == text.content.len() => cursor = 0, + _ => cursor -= text.content.len(), + } + + (cursor, acc) + }) + .1 } } @@ -79,9 +98,11 @@ impl RichTextWithInvisible { |(buffer, state, acc), byte| match state { State::None => ( vec![byte], - Self::is_visible(byte) - .then_some(State::Visible) - .unwrap_or(State::Invisible), + if Self::is_visible(byte) { + State::Visible + } else { + State::Invisible + }, acc, ), State::Visible => { @@ -140,7 +161,7 @@ impl RichTextWithInvisible { } fn is_visible(byte: u8) -> bool { - 0x20 <= byte && byte <= 0x7E + (0x20..=0x7E).contains(&byte) } fn bytes_to_rich(bytes: Vec) -> Vec { diff --git a/src/text.rs b/src/text.rs index 26434c1..9bc9b87 100644 --- a/src/text.rs +++ b/src/text.rs @@ -77,13 +77,7 @@ impl TextView { ); let content = vec![timestamp_span] .into_iter() - .chain(data.iter().enumerate().map(|(i, rich_text)| { - if i == 0 { - rich_text.crop_prefix_len(scroll.1 as usize).to_span() - } else { - rich_text.to_span() - } - })) + .chain(RichText::crop_rich_texts(data, scroll.1 as usize)) .collect::>(); Line::from(content) From 6d00d5c9d54e424a2d0e9205273babf55d4b5f06 Mon Sep 17 00:00:00 2001 From: "Matheus T. dos Santos" Date: Fri, 15 Mar 2024 09:03:18 -0300 Subject: [PATCH 2/4] fix: :bug: fix windows build --- .github/workflows/rust.yml | 15 +++----- Cargo.lock | 72 ++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 +- 3 files changed, 78 insertions(+), 11 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 2991d28..172ee00 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -15,10 +15,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Install libudev-sys and Lua5.4 - run: sudo apt-get install -y libudev-dev liblua5.4-dev + - name: Install libudev-sys + run: sudo apt-get install -y libudev-dev - name: Build - run: cargo build --verbose + run: cargo build --release --verbose build-windows: name: Check on Windows runs-on: windows-latest @@ -26,18 +26,13 @@ jobs: run: shell: msys2 {0} steps: - - uses: msys2/setup-msys2@v2 - uses: actions/checkout@v3 - - name: Install Rust & Lua - run: pacman -S --noconfirm mingw-w64-x86_64-rust mingw-w64-x86_64-lua mingw-w64-x86_64-luajit mingw-w64-x86_64-pkg-config - name: Build - run: cargo build --verbose + run: cargo build --release --verbose build-macos: name: Check on MacOS runs-on: macos-latest steps: - uses: actions/checkout@v3 - - name: Install Lua5.4 - run: brew install lua - name: Build - run: cargo build --verbose + run: cargo build --release --verbose diff --git a/Cargo.lock b/Cargo.lock index 431868a..ca4f9e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -329,6 +329,16 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "errno" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "futures" version = "0.3.30" @@ -457,6 +467,15 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "homedir" version = "0.2.1" @@ -550,6 +569,12 @@ version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +[[package]] +name = "linux-raw-sys" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" + [[package]] name = "lock_api" version = "0.4.11" @@ -575,6 +600,25 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "lua-src" +version = "546.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2da0daa7eee611a4c30c8f5ee31af55266e26e573971ba9336d2993e2da129b2" +dependencies = [ + "cc", +] + +[[package]] +name = "luajit-src" +version = "210.5.6+9cc2e42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b365d859c9ffc187f48bb3e25ec80c3b40cf3f68f53544f4adeaee70554157" +dependencies = [ + "cc", + "which", +] + [[package]] name = "mach2" version = "0.4.2" @@ -655,6 +699,8 @@ checksum = "2847b42764435201d8cbee1f517edb79c4cca4181877b90047587c89e1b7bce4" dependencies = [ "cc", "cfg-if", + "lua-src", + "luajit-src", "pkg-config", ] @@ -888,6 +934,19 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustix" +version = "0.38.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" +dependencies = [ + "bitflags 2.4.2", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + [[package]] name = "rustversion" version = "1.0.14" @@ -1267,6 +1326,19 @@ version = "0.2.91" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838" +[[package]] +name = "which" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fa5e0c10bf77f44aac573e498d1a82d5fbd5e91f6fc0a99e7be4b38e85e101c" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", + "windows-sys 0.52.0", +] + [[package]] name = "widestring" version = "1.0.2" diff --git a/Cargo.toml b/Cargo.toml index 191145d..b759450 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ serde = "1.0" serde_yaml = "0.9" rand = "0.8.5" clap = { version = "4.1.9", features = ["derive"] } -mlua = { version = "0.9.6", features = ["lua54", "async", "send"] } +mlua = { version = "0.9.6", features = ["lua54", "vendored", "async", "send"] } anyhow = "1.0.79" homedir = "0.2.1" regex = { version = "1.10.3", features = [] } From 8db363c045fb8d5c6a39155e7885c0607878658d Mon Sep 17 00:00:00 2001 From: "Matheus T. dos Santos" Date: Fri, 15 Mar 2024 10:02:44 -0300 Subject: [PATCH 3/4] fix: fix windows double press and change back horizontal scroll to control modifier --- src/command_bar.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/command_bar.rs b/src/command_bar.rs index b254b6f..bfcdf7f 100644 --- a/src/command_bar.rs +++ b/src/command_bar.rs @@ -5,7 +5,9 @@ use crate::plugin_manager::PluginManager; use crate::serial::SerialIF; use crate::text::TextView; use chrono::Local; -use crossterm::event::{Event, EventStream, KeyCode, KeyEvent, KeyModifiers, MouseEventKind}; +use crossterm::event::{ + Event, EventStream, KeyCode, KeyEvent, KeyEventKind, KeyModifiers, MouseEventKind, +}; use futures::StreamExt; use rand::seq::SliceRandom; use ratatui::layout::{Constraint, Direction, Layout, Rect}; @@ -92,14 +94,16 @@ impl CommandBar { match event { Some(Ok(event)) => match event { - Event::Mouse(mouse_evt) if mouse_evt.modifiers == KeyModifiers::SHIFT => { + Event::Mouse(mouse_evt) if mouse_evt.modifiers == KeyModifiers::CONTROL => { match mouse_evt.kind { MouseEventKind::ScrollUp => sender.send(HorizontalScroll(-1)).unwrap(), MouseEventKind::ScrollDown => sender.send(HorizontalScroll(1)).unwrap(), _ => {} } } - Event::Key(key) => sender.send(Key(key)).unwrap(), + Event::Key(key) if key.kind == KeyEventKind::Press => { + sender.send(Key(key)).unwrap() + } Event::Mouse(mouse_evt) => match mouse_evt.kind { MouseEventKind::ScrollUp => sender.send(VerticalScroll(-1)).unwrap(), MouseEventKind::ScrollDown => sender.send(VerticalScroll(1)).unwrap(), From af0dd4c9b44e99fefb74dd01259c6159cdc53e03 Mon Sep 17 00:00:00 2001 From: "Matheus T. dos Santos" Date: Fri, 15 Mar 2024 10:30:55 -0300 Subject: [PATCH 4/4] ci: remove msys2 on windows --- .github/workflows/rust.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 172ee00..c3a0e23 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -22,9 +22,6 @@ jobs: build-windows: name: Check on Windows runs-on: windows-latest - defaults: - run: - shell: msys2 {0} steps: - uses: actions/checkout@v3 - name: Build