Compare commits
2 Commits
3d47e4edd9
...
1da04a4d0c
| Author | SHA1 | Date | |
|---|---|---|---|
| 1da04a4d0c | |||
| 6f408b3c21 |
@@ -205,7 +205,7 @@ pub fn complete_builtin(node: Node, io_stack: &mut IoStack, job: &mut JobBldr) -
|
||||
}
|
||||
|
||||
pub fn compgen_builtin(node: Node, io_stack: &mut IoStack, job: &mut JobBldr) -> ShResult<()> {
|
||||
let blame = node.get_span().clone();
|
||||
let _blame = node.get_span().clone();
|
||||
let NdRule::Command {
|
||||
assignments: _,
|
||||
argv,
|
||||
|
||||
@@ -7,7 +7,7 @@ use regex::Regex;
|
||||
|
||||
use crate::libsh::error::{ShErr, ShErrKind, ShResult};
|
||||
use crate::parse::execute::exec_input;
|
||||
use crate::parse::lex::{LexFlags, LexStream, Tk, TkFlags, TkRule, is_field_sep, is_hard_sep};
|
||||
use crate::parse::lex::{LexFlags, LexStream, Tk, TkFlags, TkRule, is_hard_sep};
|
||||
use crate::parse::{Redir, RedirType};
|
||||
use crate::procio::{IoBuf, IoFrame, IoMode, IoStack};
|
||||
use crate::readline::markers;
|
||||
|
||||
11
src/jobs.rs
11
src/jobs.rs
@@ -6,7 +6,7 @@ use crate::{
|
||||
prelude::*,
|
||||
procio::{IoMode, borrow_fd},
|
||||
signal::{disable_reaping, enable_reaping},
|
||||
state::{self, read_jobs, set_status, write_jobs},
|
||||
state::{self, set_status, write_jobs},
|
||||
};
|
||||
|
||||
pub const SIG_EXIT_OFFSET: i32 = 128;
|
||||
@@ -168,12 +168,7 @@ impl JobTab {
|
||||
}
|
||||
pub fn curr_job(&self) -> Option<usize> {
|
||||
// Find the most recent valid job (order can have stale entries)
|
||||
for &id in self.order.iter().rev() {
|
||||
if self.jobs.get(id).is_some_and(|slot| slot.is_some()) {
|
||||
return Some(id);
|
||||
}
|
||||
}
|
||||
None
|
||||
self.order.iter().rev().find(|&&id| self.jobs.get(id).is_some_and(|slot| slot.is_some())).copied()
|
||||
}
|
||||
pub fn prev_job(&self) -> Option<usize> {
|
||||
// Find the second most recent valid job
|
||||
@@ -794,7 +789,7 @@ pub fn attach_tty(pgid: Pid) -> ShResult<()> {
|
||||
|
||||
match result {
|
||||
Ok(_) => Ok(()),
|
||||
Err(e) => {
|
||||
Err(_e) => {
|
||||
tcsetpgrp(borrow_fd(0), getpgrp())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use crate::{
|
||||
getopt::Opt,
|
||||
libsh::term::{Style, Styled},
|
||||
parse::lex::Span,
|
||||
prelude::*,
|
||||
@@ -423,7 +422,7 @@ impl Display for ShErrKind {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let output = match self {
|
||||
Self::IoErr(e) => &format!("I/O Error: {e}"),
|
||||
Self::InvalidOpt => &format!("Invalid option"),
|
||||
Self::InvalidOpt => "Invalid option",
|
||||
Self::SyntaxErr => "Syntax Error",
|
||||
Self::ParseErr => "Parse Error",
|
||||
Self::InternalErr => "Internal Error",
|
||||
|
||||
@@ -3,35 +3,6 @@ use std::sync::LazyLock;
|
||||
use termios::{LocalFlags, Termios};
|
||||
|
||||
use crate::prelude::*;
|
||||
///
|
||||
/// The previous state of the terminal options.
|
||||
///
|
||||
/// This variable stores the terminal settings at the start of the program and
|
||||
/// restores them when the program exits. It is initialized exactly once at the
|
||||
/// start of the program and accessed exactly once at the end of the program. It
|
||||
/// will not be mutated or accessed under any other circumstances.
|
||||
///
|
||||
/// This ended up being necessary because wrapping Termios in a thread-safe way
|
||||
/// was unreasonably tricky.
|
||||
///
|
||||
/// The possible states of this variable are:
|
||||
/// - `None`: The terminal options have not been set yet (before
|
||||
/// initialization).
|
||||
/// - `Some(None)`: There were no terminal options to save (i.e., no terminal
|
||||
/// input detected).
|
||||
/// - `Some(Some(Termios))`: The terminal options (as `Termios`) have been
|
||||
/// saved.
|
||||
///
|
||||
/// **Important:** This static variable is mutable and accessed via unsafe code.
|
||||
/// It is only safe to use because:
|
||||
/// - It is set once during program startup and accessed once during program
|
||||
/// exit.
|
||||
/// - It is not mutated or accessed after the initial setup and final read.
|
||||
///
|
||||
/// **Caution:** Future changes to this code should respect these constraints to
|
||||
/// ensure safety. Modifying or accessing this variable outside the defined
|
||||
/// lifecycle could lead to undefined behavior.
|
||||
pub(crate) static mut SAVED_TERMIOS: Option<Option<Termios>> = None;
|
||||
|
||||
pub static TTY_FILENO: LazyLock<RawFd> = LazyLock::new(|| {
|
||||
open("/dev/tty", OFlag::O_RDWR, Mode::empty()).expect("Failed to open /dev/tty")
|
||||
|
||||
@@ -84,7 +84,7 @@ impl TkVecUtils<Tk> for Vec<Tk> {
|
||||
}
|
||||
}
|
||||
fn debug_tokens(&self) {
|
||||
for token in self {}
|
||||
for _token in self {}
|
||||
}
|
||||
fn split_at_separators(&self) -> Vec<Vec<Tk>> {
|
||||
let mut splits = vec![];
|
||||
|
||||
@@ -20,7 +20,6 @@ use crate::{
|
||||
source::source,
|
||||
test::double_bracket_test,
|
||||
trap::{TrapTarget, trap},
|
||||
true_builtin,
|
||||
varcmds::{export, local, readonly, unset},
|
||||
zoltraak::zoltraak,
|
||||
},
|
||||
|
||||
@@ -15,7 +15,6 @@ use crate::{
|
||||
error::{ShErr, ShErrKind, ShResult},
|
||||
utils::CharDequeUtils,
|
||||
},
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
pub const KEYWORDS: [&str; 16] = [
|
||||
|
||||
@@ -1281,7 +1281,7 @@ impl ParseStream {
|
||||
let mut node_tks = vec![];
|
||||
let mut redirs = vec![];
|
||||
let mut argv = vec![];
|
||||
let mut flags = NdFlags::empty();
|
||||
let flags = NdFlags::empty();
|
||||
let mut assignments = vec![];
|
||||
|
||||
while let Some(prefix_tk) = tk_iter.next() {
|
||||
|
||||
@@ -1,25 +1,22 @@
|
||||
use std::{
|
||||
collections::HashSet, env, fmt::Debug, os::unix::fs::PermissionsExt, path::PathBuf, sync::Arc,
|
||||
collections::HashSet, fmt::Debug, path::PathBuf, sync::Arc,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
builtin::{
|
||||
BUILTINS,
|
||||
complete::{CompFlags, CompOptFlags, CompOpts},
|
||||
},
|
||||
builtin::complete::{CompFlags, CompOptFlags, CompOpts},
|
||||
libsh::{
|
||||
error::{ShErr, ShErrKind, ShResult},
|
||||
error::ShResult,
|
||||
utils::TkVecUtils,
|
||||
},
|
||||
parse::{
|
||||
execute::{VarCtxGuard, exec_input},
|
||||
lex::{self, LexFlags, Tk, TkFlags, TkRule, ends_with_unescaped},
|
||||
lex::{self, LexFlags, Tk, TkRule, ends_with_unescaped},
|
||||
},
|
||||
readline::{
|
||||
Marker, annotate_input, annotate_input_recursive, get_insertions,
|
||||
Marker, annotate_input_recursive,
|
||||
markers::{self, is_marker},
|
||||
},
|
||||
state::{VarFlags, VarKind, read_jobs, read_logic, read_meta, read_vars, write_vars},
|
||||
state::{VarFlags, VarKind, read_jobs, read_meta, read_vars, write_vars},
|
||||
};
|
||||
|
||||
pub fn complete_jobs(start: &str) -> Vec<String> {
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
use std::{
|
||||
env,
|
||||
os::unix::fs::PermissionsExt,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
libsh::term::{Style, StyleSet, Styled},
|
||||
libsh::term::{Style, StyleSet},
|
||||
readline::{
|
||||
annotate_input,
|
||||
markers::{self, is_marker},
|
||||
},
|
||||
state::{read_logic, read_meta, read_shopts},
|
||||
state::{read_meta, read_shopts},
|
||||
};
|
||||
|
||||
/// Syntax highlighter for shell input using Unicode marker-based annotation
|
||||
@@ -442,3 +441,9 @@ impl Highlighter {
|
||||
.replace(markers::OPERATOR, "\x1b[35m");
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Highlighter {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,14 +9,11 @@ use std::{
|
||||
time::{Duration, SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::{
|
||||
libsh::error::{ShErr, ShErrKind, ShResult},
|
||||
readline::linebuf::LineBuf,
|
||||
};
|
||||
|
||||
use super::vicmd::Direction; // surprisingly useful
|
||||
|
||||
#[derive(Default, Clone, Copy, Debug)]
|
||||
pub enum SearchKind {
|
||||
Fuzzy,
|
||||
@@ -215,7 +212,7 @@ pub struct History {
|
||||
search_mask: Vec<HistEntry>,
|
||||
no_matches: bool,
|
||||
pub cursor: usize,
|
||||
search_direction: Direction,
|
||||
//search_direction: Direction,
|
||||
ignore_dups: bool,
|
||||
max_size: Option<u32>,
|
||||
}
|
||||
@@ -242,7 +239,7 @@ impl History {
|
||||
search_mask,
|
||||
no_matches: false,
|
||||
cursor,
|
||||
search_direction: Direction::Backward,
|
||||
//search_direction: Direction::Backward,
|
||||
ignore_dups,
|
||||
max_size: Some(max_hist as u32),
|
||||
})
|
||||
|
||||
@@ -11,10 +11,7 @@ use super::vicmd::{
|
||||
ViCmd, Word,
|
||||
};
|
||||
use crate::{
|
||||
libsh::{
|
||||
error::ShResult,
|
||||
term::{Style, Styled},
|
||||
},
|
||||
libsh::error::ShResult,
|
||||
parse::lex::{LexFlags, LexStream, Tk, TkFlags, TkRule},
|
||||
prelude::*,
|
||||
readline::{
|
||||
@@ -950,7 +947,7 @@ impl LineBuf {
|
||||
| TextObj::Angle(bound) => self.text_obj_delim(count, text_obj, bound),
|
||||
|
||||
// Other stuff
|
||||
TextObj::Tag(bound) => todo!(),
|
||||
TextObj::Tag(_bound) => todo!(),
|
||||
TextObj::Custom(_) => todo!(),
|
||||
}
|
||||
}
|
||||
@@ -1027,12 +1024,12 @@ impl LineBuf {
|
||||
|
||||
Some((start, end))
|
||||
}
|
||||
pub fn text_obj_paragraph(&mut self, count: usize, bound: Bound) -> Option<(usize, usize)> {
|
||||
pub fn text_obj_paragraph(&mut self, _count: usize, _bound: Bound) -> Option<(usize, usize)> {
|
||||
todo!()
|
||||
}
|
||||
pub fn text_obj_delim(
|
||||
&mut self,
|
||||
count: usize,
|
||||
_count: usize,
|
||||
text_obj: TextObj,
|
||||
bound: Bound,
|
||||
) -> Option<(usize, usize)> {
|
||||
@@ -1149,7 +1146,7 @@ impl LineBuf {
|
||||
}
|
||||
pub fn text_obj_quote(
|
||||
&mut self,
|
||||
count: usize,
|
||||
_count: usize,
|
||||
text_obj: TextObj,
|
||||
bound: Bound,
|
||||
) -> Option<(usize, usize)> {
|
||||
@@ -2285,14 +2282,14 @@ impl LineBuf {
|
||||
|
||||
MotionKind::On(target_pos)
|
||||
}
|
||||
MotionCmd(count, Motion::ScreenLineUp) => todo!(),
|
||||
MotionCmd(count, Motion::ScreenLineUpCharwise) => todo!(),
|
||||
MotionCmd(count, Motion::ScreenLineDown) => todo!(),
|
||||
MotionCmd(count, Motion::ScreenLineDownCharwise) => todo!(),
|
||||
MotionCmd(count, Motion::BeginningOfScreenLine) => todo!(),
|
||||
MotionCmd(count, Motion::FirstGraphicalOnScreenLine) => todo!(),
|
||||
MotionCmd(count, Motion::HalfOfScreen) => todo!(),
|
||||
MotionCmd(count, Motion::HalfOfScreenLineText) => todo!(),
|
||||
MotionCmd(_count, Motion::ScreenLineUp) => todo!(),
|
||||
MotionCmd(_count, Motion::ScreenLineUpCharwise) => todo!(),
|
||||
MotionCmd(_count, Motion::ScreenLineDown) => todo!(),
|
||||
MotionCmd(_count, Motion::ScreenLineDownCharwise) => todo!(),
|
||||
MotionCmd(_count, Motion::BeginningOfScreenLine) => todo!(),
|
||||
MotionCmd(_count, Motion::FirstGraphicalOnScreenLine) => todo!(),
|
||||
MotionCmd(_count, Motion::HalfOfScreen) => todo!(),
|
||||
MotionCmd(_count, Motion::HalfOfScreenLineText) => todo!(),
|
||||
MotionCmd(_count, Motion::WholeBuffer) => {
|
||||
MotionKind::Exclusive((0, self.grapheme_indices().len()))
|
||||
}
|
||||
@@ -2314,9 +2311,9 @@ impl LineBuf {
|
||||
final_end = final_end.min(self.cursor.max);
|
||||
MotionKind::Exclusive((start, final_end))
|
||||
}
|
||||
MotionCmd(count, Motion::RepeatMotion) => todo!(),
|
||||
MotionCmd(count, Motion::RepeatMotionRev) => todo!(),
|
||||
MotionCmd(count, Motion::Null) => MotionKind::Null,
|
||||
MotionCmd(_count, Motion::RepeatMotion) => todo!(),
|
||||
MotionCmd(_count, Motion::RepeatMotionRev) => todo!(),
|
||||
MotionCmd(_count, Motion::Null) => MotionKind::Null,
|
||||
};
|
||||
|
||||
self.set_buffer(buffer);
|
||||
@@ -2380,7 +2377,7 @@ impl LineBuf {
|
||||
end = self.cursor.get();
|
||||
}
|
||||
},
|
||||
SelectMode::Block(anchor) => todo!(),
|
||||
SelectMode::Block(_anchor) => todo!(),
|
||||
}
|
||||
if start >= end {
|
||||
mode.invert_anchor();
|
||||
@@ -2490,7 +2487,7 @@ impl LineBuf {
|
||||
match verb {
|
||||
Verb::Delete | Verb::Yank | Verb::Change => {
|
||||
log::debug!("Executing verb: {verb:?} with motion: {motion:?}");
|
||||
let Some((mut start, mut end)) = self.range_from_motion(&motion) else {
|
||||
let Some((start, end)) = self.range_from_motion(&motion) else {
|
||||
log::debug!("No range from motion, nothing to do");
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use history::History;
|
||||
use keys::{KeyCode, KeyEvent, ModKeys};
|
||||
use linebuf::{LineBuf, SelectAnchor, SelectMode};
|
||||
use nix::libc::STDOUT_FILENO;
|
||||
use term::{KeyReader, Layout, LineWriter, PollReader, TermWriter, get_win_size};
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
use vicmd::{CmdFlags, Motion, MotionCmd, RegisterName, Verb, VerbCmd, ViCmd};
|
||||
@@ -14,10 +13,7 @@ use crate::prelude::*;
|
||||
use crate::readline::term::{Pos, calc_str_width};
|
||||
use crate::state::read_shopts;
|
||||
use crate::{
|
||||
libsh::{
|
||||
error::ShResult,
|
||||
term::{Style, Styled},
|
||||
},
|
||||
libsh::error::ShResult,
|
||||
parse::lex::{self, LexFlags, Tk, TkFlags, TkRule},
|
||||
readline::{complete::Completer, highlight::Highlighter},
|
||||
};
|
||||
|
||||
@@ -8,7 +8,7 @@ use std::{
|
||||
|
||||
use nix::{
|
||||
errno::Errno,
|
||||
libc::{self, STDIN_FILENO},
|
||||
libc::{self},
|
||||
poll::{self, PollFlags, PollTimeout},
|
||||
sys::termios::{self, tcgetattr, tcsetattr},
|
||||
unistd::isatty,
|
||||
@@ -23,16 +23,14 @@ use crate::{
|
||||
sys::TTY_FILENO,
|
||||
},
|
||||
readline::keys::{KeyCode, ModKeys},
|
||||
shopt::ShedBellStyle,
|
||||
state::read_shopts,
|
||||
};
|
||||
use crate::{
|
||||
prelude::*,
|
||||
procio::borrow_fd,
|
||||
state::{read_meta, write_meta},
|
||||
};
|
||||
|
||||
use super::{keys::KeyEvent, linebuf::LineBuf};
|
||||
use super::keys::KeyEvent;
|
||||
|
||||
pub fn raw_mode() -> RawModeGuard {
|
||||
let orig = termios::tcgetattr(unsafe { BorrowedFd::borrow_raw(*TTY_FILENO) })
|
||||
@@ -50,7 +48,7 @@ pub fn raw_mode() -> RawModeGuard {
|
||||
)
|
||||
.expect("Failed to set terminal to raw mode");
|
||||
|
||||
let (cols, rows) = get_win_size(*TTY_FILENO);
|
||||
let (_cols, _rows) = get_win_size(*TTY_FILENO);
|
||||
|
||||
RawModeGuard {
|
||||
orig,
|
||||
@@ -859,18 +857,15 @@ pub struct TermWriter {
|
||||
out: RawFd,
|
||||
pub t_cols: Col, // terminal width
|
||||
buffer: String,
|
||||
w_calc: Box<dyn WidthCalculator>,
|
||||
}
|
||||
|
||||
impl TermWriter {
|
||||
pub fn new(out: RawFd) -> Self {
|
||||
let w_calc = width_calculator();
|
||||
let (t_cols, _) = get_win_size(out);
|
||||
Self {
|
||||
out,
|
||||
t_cols,
|
||||
buffer: String::new(),
|
||||
w_calc,
|
||||
}
|
||||
}
|
||||
pub fn get_cursor_movement(&self, old: Pos, new: Pos) -> ShResult<String> {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use std::iter::Peekable;
|
||||
use std::str::Chars;
|
||||
|
||||
use nix::NixPath;
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
|
||||
use super::keys::{KeyCode as K, KeyEvent as E, ModKeys as M};
|
||||
@@ -9,7 +8,6 @@ use super::vicmd::{
|
||||
Anchor, Bound, CmdFlags, Dest, Direction, Motion, MotionCmd, RegisterName, TextObj, To, Verb,
|
||||
VerbCmd, ViCmd, Word,
|
||||
};
|
||||
use crate::prelude::*;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum ModeReport {
|
||||
@@ -995,7 +993,7 @@ impl ViNormal {
|
||||
}
|
||||
};
|
||||
|
||||
if chars.peek().is_some() {}
|
||||
let _ = chars; // suppresses unused warnings, creates an error if we decide to use chars later
|
||||
|
||||
let verb_ref = verb.as_ref().map(|v| &v.1);
|
||||
let motion_ref = motion.as_ref().map(|m| &m.1);
|
||||
@@ -1660,7 +1658,7 @@ impl ViVisual {
|
||||
}
|
||||
};
|
||||
|
||||
if chars.peek().is_some() {}
|
||||
let _ = chars; // suppresses unused warnings, creates an error if we decide to use chars later
|
||||
|
||||
let verb_ref = verb.as_ref().map(|v| &v.1);
|
||||
let motion_ref = motion.as_ref().map(|m| &m.1);
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
use std::{collections::HashMap, fmt::Display, str::FromStr};
|
||||
use std::{fmt::Display, str::FromStr};
|
||||
|
||||
use crate::{
|
||||
libsh::error::{Note, ShErr, ShErrKind, ShResult},
|
||||
state::ShFunc,
|
||||
};
|
||||
use crate::libsh::error::{Note, ShErr, ShErrKind, ShResult};
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum ShedBellStyle {
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
cmp::Ordering,
|
||||
collections::{HashMap, HashSet, VecDeque, hash_map::Entry},
|
||||
fmt::Display,
|
||||
ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, Deref},
|
||||
ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign},
|
||||
os::unix::fs::PermissionsExt,
|
||||
str::FromStr,
|
||||
time::Duration,
|
||||
@@ -1052,7 +1051,7 @@ impl MetaTab {
|
||||
&mut self.comp_specs
|
||||
}
|
||||
pub fn get_comp_spec(&self, cmd: &str) -> Option<Box<dyn CompSpec>> {
|
||||
self.comp_specs.get(cmd).map(|spec| spec.clone())
|
||||
self.comp_specs.get(cmd).cloned()
|
||||
}
|
||||
pub fn set_comp_spec(&mut self, cmd: String, spec: Box<dyn CompSpec>) {
|
||||
self.comp_specs.insert(cmd, spec);
|
||||
|
||||
Reference in New Issue
Block a user