Skip to content

Commit 3df9e7c

Browse files
authored
Fix multiple issues found under Linux (#706)
Fixed: * `sighandler_t` warning in nightly * cppdbg + gdb pretty printing * UTF8 parsing for SGR mouse coords
1 parent d71e94b commit 3df9e7c

4 files changed

Lines changed: 34 additions & 28 deletions

File tree

.vscode/launch.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,20 @@
1010
"program": "${workspaceFolder}/target/debug/edit",
1111
"cwd": "${workspaceFolder}",
1212
"args": [
13-
"${workspaceFolder}/src/bin/edit/main.rs"
13+
"${workspaceFolder}/crates/edit/src/bin/edit/main.rs"
1414
],
1515
},
1616
{
17-
"name": "Launch Debug (GDB/LLDB)",
17+
"name": "Launch Debug (GDB)",
1818
"preLaunchTask": "rust: cargo build",
1919
"type": "cppdbg",
2020
"request": "launch",
21+
"miDebuggerPath": "rust-gdb",
22+
"externalConsole": true,
2123
"program": "${workspaceFolder}/target/debug/edit",
2224
"cwd": "${workspaceFolder}",
2325
"args": [
24-
"${workspaceFolder}/src/bin/edit/main.rs"
26+
"${workspaceFolder}/crates/edit/src/bin/edit/main.rs"
2527
],
2628
},
2729
{
@@ -32,7 +34,7 @@
3234
"program": "${workspaceFolder}/target/debug/edit",
3335
"cwd": "${workspaceFolder}",
3436
"args": [
35-
"${workspaceFolder}/src/bin/edit/main.rs"
37+
"${workspaceFolder}/crates/edit/src/bin/edit/main.rs"
3638
],
3739
}
3840
]

crates/edit/src/input.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ pub struct Parser {
268268
bracketed_paste: bool,
269269
bracketed_paste_buf: Vec<u8>,
270270
x10_mouse_want: bool,
271-
x10_mouse_buf: [u8; 3],
271+
x10_mouse_buf: [char; 3],
272272
x10_mouse_len: usize,
273273
}
274274

@@ -281,7 +281,7 @@ impl Parser {
281281
bracketed_paste: false,
282282
bracketed_paste_buf: Vec::new(),
283283
x10_mouse_want: false,
284-
x10_mouse_buf: [0; 3],
284+
x10_mouse_buf: ['\0'; 3],
285285
x10_mouse_len: 0,
286286
}
287287
}
@@ -535,27 +535,35 @@ impl<'input> Stream<'_, '_, 'input> {
535535
/// This is so puzzling to me. The existence of this function makes me unhappy.
536536
#[cold]
537537
fn parse_x10_mouse_coordinates(&mut self) -> Option<Input<'input>> {
538-
self.parser.x10_mouse_len +=
539-
self.stream.read(&mut self.parser.x10_mouse_buf[self.parser.x10_mouse_len..]);
538+
while self.parser.x10_mouse_len < 3 && !self.stream.done() {
539+
self.parser.x10_mouse_buf[self.parser.x10_mouse_len] = self.stream.next_char();
540+
self.parser.x10_mouse_len += 1;
541+
}
540542
if self.parser.x10_mouse_len < 3 {
541543
return None;
542544
}
543545

544-
let button = self.parser.x10_mouse_buf[0] & 0b11;
545-
let modifier = self.parser.x10_mouse_buf[0] & 0b11100;
546+
let b = self.parser.x10_mouse_buf[0] as u32;
546547
let x = self.parser.x10_mouse_buf[1] as CoordType - 0x21;
547548
let y = self.parser.x10_mouse_buf[2] as CoordType - 0x21;
548-
let action = match button {
549+
let action = match b & 0b11 {
549550
0 => InputMouseState::Left,
550551
1 => InputMouseState::Middle,
551552
2 => InputMouseState::Right,
552553
_ => InputMouseState::None,
553554
};
554-
let modifiers = match modifier {
555-
4 => kbmod::SHIFT,
556-
8 => kbmod::ALT,
557-
16 => kbmod::CTRL,
558-
_ => kbmod::NONE,
555+
let modifiers = {
556+
let mut m = kbmod::NONE;
557+
if (b & 0b00100) != 0 {
558+
m |= kbmod::SHIFT;
559+
}
560+
if (b & 0b01000) != 0 {
561+
m |= kbmod::ALT;
562+
}
563+
if (b & 0b10000) != 0 {
564+
m |= kbmod::CTRL;
565+
}
566+
m
559567
};
560568

561569
self.parser.x10_mouse_want = false;

crates/edit/src/sys/unix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub fn switch_modes() -> apperr::Result<()> {
6363

6464
// Set STATE.inject_resize to true whenever we get a SIGWINCH.
6565
let mut sigwinch_action: libc::sigaction = mem::zeroed();
66-
sigwinch_action.sa_sigaction = sigwinch_handler as libc::sighandler_t;
66+
sigwinch_action.sa_sigaction = sigwinch_handler as *const () as libc::sighandler_t;
6767
check_int_return(libc::sigaction(libc::SIGWINCH, &sigwinch_action, null_mut()))?;
6868

6969
// Get the original terminal modes so we can disable raw mode on exit.

crates/edit/src/vt.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,13 @@ impl<'input> Stream<'_, 'input> {
128128
self.off
129129
}
130130

131-
/// Reads and consumes raw bytes from the input.
132-
pub fn read(&mut self, dst: &mut [u8]) -> usize {
133-
let bytes = self.input.as_bytes();
134-
let off = self.off.min(bytes.len());
135-
let len = dst.len().min(bytes.len() - off);
136-
dst[..len].copy_from_slice(&bytes[off..off + len]);
137-
self.off += len;
138-
len
131+
/// Returns `true` if the input has been fully parsed.
132+
pub fn done(&self) -> bool {
133+
self.off >= self.input.len()
139134
}
140135

141-
fn decode_next(&mut self) -> char {
136+
/// Decodes and consumes the next UTF-8 character from the input.
137+
pub fn next_char(&mut self) -> char {
142138
let mut iter = Utf8Chars::new(self.input.as_bytes(), self.off);
143139
let c = iter.next().unwrap_or('\0');
144140
self.off = iter.offset();
@@ -190,7 +186,7 @@ impl<'input> Stream<'_, 'input> {
190186
return Some(Token::Text(&input[beg..self.off]));
191187
}
192188
},
193-
State::Esc => match self.decode_next() {
189+
State::Esc => match self.next_char() {
194190
'[' => {
195191
self.parser.state = State::Csi;
196192
self.parser.csi.private_byte = '\0';
@@ -216,7 +212,7 @@ impl<'input> Stream<'_, 'input> {
216212
},
217213
State::Ss3 => {
218214
self.parser.state = State::Ground;
219-
return Some(Token::SS3(self.decode_next()));
215+
return Some(Token::SS3(self.next_char()));
220216
}
221217
State::Csi => {
222218
loop {

0 commit comments

Comments
 (0)