summaryrefslogtreecommitdiffstats
path: root/src/line.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/line.rs')
-rw-r--r--src/line.rs21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/line.rs b/src/line.rs
index 9877c48..e178f5b 100644
--- a/src/line.rs
+++ b/src/line.rs
@@ -1,3 +1,10 @@
1/*
2 * This file is part of agent686
3 * Copyright (C) 2026 Salmonik <salmon@2137697.xyz>
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 * https://git.2137697.xyz/agent686
6 */
7
1use std::io::{self, IsTerminal, Write}; 8use std::io::{self, IsTerminal, Write};
2use std::os::unix::fs::PermissionsExt; 9use std::os::unix::fs::PermissionsExt;
3use std::path::PathBuf; 10use std::path::PathBuf;
@@ -5,8 +12,8 @@ use std::path::PathBuf;
5use crossterm::cursor::{MoveToColumn, MoveUp}; 12use crossterm::cursor::{MoveToColumn, MoveUp};
6use crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers}; 13use crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers};
7use crossterm::event::{DisableBracketedPaste, EnableBracketedPaste}; 14use crossterm::event::{DisableBracketedPaste, EnableBracketedPaste};
8use crossterm::terminal::{self, Clear, ClearType};
9use crossterm::execute; 15use crossterm::execute;
16use crossterm::terminal::{self, Clear, ClearType};
10 17
11const HISTORY_LIMIT: usize = 200; 18const HISTORY_LIMIT: usize = 200;
12 19
@@ -311,12 +318,7 @@ struct DrawState {
311 cursor_row: usize, 318 cursor_row: usize,
312} 319}
313 320
314fn draw( 321fn draw(prompt: &str, buffer: &[char], cursor: usize, state: &mut DrawState) -> io::Result<()> {
315 prompt: &str,
316 buffer: &[char],
317 cursor: usize,
318 state: &mut DrawState,
319) -> io::Result<()> {
320 let mut out = io::stdout(); 322 let mut out = io::stdout();
321 draw_to(&mut out, prompt, buffer, cursor, state)?; 323 draw_to(&mut out, prompt, buffer, cursor, state)?;
322 out.flush() 324 out.flush()
@@ -396,7 +398,10 @@ fn load_history() -> Vec<String> {
396 lines.drain(..lines.len() - HISTORY_LIMIT); 398 lines.drain(..lines.len() - HISTORY_LIMIT);
397 // Keep the file from growing without bound, not just the in-memory list. 399 // Keep the file from growing without bound, not just the in-memory list.
398 if lines.len() * 2 < text.lines().count() { 400 if lines.len() * 2 < text.lines().count() {
399 let body: Vec<String> = lines.iter().map(|line| line.replace('\n', "\u{0}")).collect(); 401 let body: Vec<String> = lines
402 .iter()
403 .map(|line| line.replace('\n', "\u{0}"))
404 .collect();
400 let _ = std::fs::write(&path, format!("{}\n", body.join("\n"))); 405 let _ = std::fs::write(&path, format!("{}\n", body.join("\n")));
401 } 406 }
402 } 407 }