diff options
| author | salmonik <salmon@2137697.xyz> | 2026-11-23 20:36:22 +0100 |
|---|---|---|
| committer | salmonik <salmon@2137697.xyz> | 2026-11-23 20:36:22 +0100 |
| commit | e803aa488c3a95193d3e3ae358b640c299f8f121 (patch) | |
| tree | 0af80401445159ca40a8ab3d7bbf39094ab5db77 /src/line.rs | |
| parent | 0.12.1: accept `command` as an alias for `cmd` in bash (diff) | |
| download | agent686-e803aa488c3a95193d3e3ae358b640c299f8f121.tar.gz agent686-e803aa488c3a95193d3e3ae358b640c299f8f121.zip | |
License
Diffstat (limited to 'src/line.rs')
| -rw-r--r-- | src/line.rs | 21 |
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 | |||
| 1 | use std::io::{self, IsTerminal, Write}; | 8 | use std::io::{self, IsTerminal, Write}; |
| 2 | use std::os::unix::fs::PermissionsExt; | 9 | use std::os::unix::fs::PermissionsExt; |
| 3 | use std::path::PathBuf; | 10 | use std::path::PathBuf; |
| @@ -5,8 +12,8 @@ use std::path::PathBuf; | |||
| 5 | use crossterm::cursor::{MoveToColumn, MoveUp}; | 12 | use crossterm::cursor::{MoveToColumn, MoveUp}; |
| 6 | use crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers}; | 13 | use crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers}; |
| 7 | use crossterm::event::{DisableBracketedPaste, EnableBracketedPaste}; | 14 | use crossterm::event::{DisableBracketedPaste, EnableBracketedPaste}; |
| 8 | use crossterm::terminal::{self, Clear, ClearType}; | ||
| 9 | use crossterm::execute; | 15 | use crossterm::execute; |
| 16 | use crossterm::terminal::{self, Clear, ClearType}; | ||
| 10 | 17 | ||
| 11 | const HISTORY_LIMIT: usize = 200; | 18 | const HISTORY_LIMIT: usize = 200; |
| 12 | 19 | ||
| @@ -311,12 +318,7 @@ struct DrawState { | |||
| 311 | cursor_row: usize, | 318 | cursor_row: usize, |
| 312 | } | 319 | } |
| 313 | 320 | ||
| 314 | fn draw( | 321 | fn 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 | } |
