rename curses module to terminal

There's no actual use of curses here, just terminfo.
This commit is contained in:
David Adam
2025-02-12 13:36:58 +08:00
parent ffdec4b485
commit 4cb5927e7a
8 changed files with 31 additions and 33 deletions

View File

@@ -3,8 +3,8 @@
use super::prelude::*;
use crate::color::RgbColor;
use crate::common::str2wcstring;
use crate::curses::{self, Term};
use crate::output::{self, Outputter};
use crate::terminal::{self, Term};
#[allow(clippy::too_many_arguments)]
fn print_modifiers(
@@ -76,7 +76,7 @@ fn print_colors(
&named_colors
};
let term = curses::term();
let term = terminal::term();
for color_name in args {
if streams.out_is_terminal() {
if let Some(term) = term.as_ref() {
@@ -217,7 +217,7 @@ pub fn set_color(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -
// Test if we have at least basic support for setting fonts, colors and related bits - otherwise
// just give up...
let Some(term) = curses::term() else {
let Some(term) = terminal::term() else {
return STATUS_CMD_ERROR;
};
let Some(exit_attribute_mode) = &term.exit_attribute_mode else {

View File

@@ -1,6 +1,5 @@
use crate::common::ToCString;
use crate::complete::complete_invalidate_path;
use crate::curses::{self, Term};
use crate::env::{setenv_lock, unsetenv_lock, EnvMode, EnvStack, Environment};
use crate::env::{DEFAULT_READ_BYTE_LIMIT, READ_BYTE_LIMIT, TERM_HAS_XN};
use crate::flog::FLOG;
@@ -14,6 +13,7 @@
};
use crate::screen::screen_set_midnight_commander_hack;
use crate::screen::LAYOUT_CACHE_SHARED;
use crate::terminal::{self, Term};
use crate::wchar::prelude::*;
use crate::wutil::fish_wcstoi;
use std::borrow::Cow;
@@ -50,7 +50,7 @@
}
for name in CURSES_VARIABLES {
table.add_anon(name, handle_curses_change);
table.add_anon(name, handle_term_change);
}
table.add(L!("TZ"), handle_tz_change);
@@ -299,9 +299,9 @@ fn handle_locale_change(vars: &EnvStack) {
guess_emoji_width(vars);
}
fn handle_curses_change(vars: &EnvStack) {
fn handle_term_change(vars: &EnvStack) {
guess_emoji_width(vars);
init_curses(vars);
init_terminal(vars);
}
fn handle_fish_use_posix_spawn_change(vars: &EnvStack) {
@@ -361,7 +361,7 @@ pub fn env_dispatch_init(vars: &EnvStack) {
/// Runs the subset of dispatch functions that need to be called at startup.
fn run_inits(vars: &EnvStack) {
init_locale(vars);
init_curses(vars);
init_terminal(vars);
guess_emoji_width(vars);
update_wait_on_escape_ms(vars);
update_wait_on_sequence_key_ms(vars);
@@ -379,7 +379,7 @@ fn update_fish_color_support(vars: &EnvStack) {
.get(L!("TERM"))
.map(|v| v.as_string())
.unwrap_or_else(WString::new);
let max_colors = curses::term().and_then(|term| term.max_colors);
let max_colors = terminal::term().and_then(|term| term.max_colors);
let mut supports_256color = false;
let mut supports_24bit = false;
@@ -494,7 +494,7 @@ fn update_fish_color_support(vars: &EnvStack) {
crate::output::set_color_support(color_support);
}
/// Apply any platform- or environment-specific hacks to our curses [`Term`] instance.
/// Apply any platform- or environment-specific hacks to our terminfo [`Term`] instance.
fn apply_term_hacks(vars: &EnvStack, term: &mut Term) {
if cfg!(target_os = "macos") {
// Hack in missing italics and dim capabilities omitted from macOS xterm-256color terminfo.
@@ -535,8 +535,8 @@ fn apply_non_term_hacks(vars: &EnvStack) {
}
}
// Initialize the curses subsystem
fn init_curses(vars: &EnvStack) {
// Initialize the terminal subsystem
fn init_terminal(vars: &EnvStack) {
for var_name in CURSES_VARIABLES {
if let Some(value) = vars
.getf_unless_empty(var_name, EnvMode::EXPORT)
@@ -550,7 +550,7 @@ fn init_curses(vars: &EnvStack) {
}
}
if curses::setup(None, |term| apply_term_hacks(vars, term)).is_none() {
if terminal::setup(None, |term| apply_term_hacks(vars, term)).is_none() {
if is_interactive_session() {
let term = vars.get_unless_empty(L!("TERM")).map(|v| v.as_string());
// We do not warn for xterm-256color at all, we know that one.
@@ -569,14 +569,14 @@ fn init_curses(vars: &EnvStack) {
}
}
curses::setup_fallback_term();
terminal::setup_fallback_term();
}
// Configure hacks that apply regardless of whether we successfully init curses or not.
// Configure hacks that apply regardless of whether we successfully init
apply_non_term_hacks(vars);
// Store some global variables that reflect the term's capabilities
if let Some(term) = curses::term() {
if let Some(term) = terminal::term() {
TERM_HAS_XN.store(term.eat_newline_glitch, Ordering::Relaxed);
}

View File

@@ -1,5 +1,4 @@
use crate::common::{escape, get_by_sorted_name, str2wcstring, Named};
use crate::curses;
use crate::env::Environment;
use crate::event;
use crate::flog::FLOG;
@@ -18,6 +17,7 @@
reader_reading_interrupted, reader_reset_interrupted, reader_schedule_prompt_repaint, Reader,
};
use crate::signal::signal_clear_cancel;
use crate::terminal;
use crate::threads::{assert_is_main_thread, iothread_service_main};
use crate::wchar::prelude::*;
use once_cell::sync::{Lazy, OnceCell};
@@ -1022,8 +1022,8 @@ pub fn get<'a>(
/// Create a list of terminfo mappings.
fn create_input_terminfo() -> Box<[TerminfoMapping]> {
let Some(term) = curses::term() else {
// setupterm() failed so we can't reference any key definitions.
let Some(term) = terminal::term() else {
// loading terminfo failed so we can't reference any key definitions.
return Box::new([]);
};

View File

@@ -34,7 +34,6 @@
pub mod builtins;
pub mod color;
pub mod complete;
pub mod curses;
pub mod editable_line;
pub mod env;
pub mod env_dispatch;
@@ -84,6 +83,7 @@
pub mod redirection;
pub mod screen;
pub mod signal;
pub mod terminal;
pub mod termsize;
pub mod threads;
pub mod timer;

View File

@@ -1,8 +1,8 @@
// Generic output functions.
use crate::color::RgbColor;
use crate::common::{self, wcs2string_appending};
use crate::curses::{self, tparm1, Term};
use crate::env::EnvVar;
use crate::terminal::{self, tparm1, Term};
use crate::threads::MainThread;
use crate::wchar::prelude::*;
use bitflags::bitflags;
@@ -164,7 +164,7 @@ fn maybe_flush(&mut self) {
/// Unconditionally write the color string to the output.
/// Exported for builtin_set_color's usage only.
pub fn write_color(&mut self, color: RgbColor, is_fg: bool) -> bool {
let Some(term) = curses::term() else {
let Some(term) = terminal::term() else {
return false;
};
let term: &Term = &term;
@@ -215,7 +215,7 @@ pub fn write_color(&mut self, color: RgbColor, is_fg: bool) -> bool {
pub fn set_color(&mut self, mut fg: RgbColor, mut bg: RgbColor) {
// Test if we have at least basic support for setting fonts, colors and related bits - otherwise
// just give up...
let Some(term) = curses::term() else {
let Some(term) = terminal::term() else {
return;
};
let term: &Term = &term;
@@ -351,7 +351,7 @@ pub fn set_color(&mut self, mut fg: RgbColor, mut bg: RgbColor) {
if is_dim && !self.was_dim && self.tputs_if_some(enter_dim_mode) {
self.was_dim = is_dim;
}
// N.B. there is no exit_dim_mode in curses, it's handled by exit_attribute_mode above.
// N.B. there is no exit_dim_mode in terminfo, it's handled by exit_attribute_mode above.
if is_reverse && !self.was_reverse {
// Some terms do not have a reverse mode set, so standout mode is a fallback.

View File

@@ -7,7 +7,6 @@
charptr2wcstring, escape, is_windows_subsystem_for_linux, redirect_tty_output,
scoped_push_replacer, timef, Timepoint, WSL,
};
use crate::curses::term;
use crate::env::Statuses;
use crate::event::{self, Event};
use crate::flog::{FLOG, FLOGF};
@@ -19,6 +18,7 @@
use crate::reader::{fish_is_unwinding_for_exit, reader_schedule_prompt_repaint};
use crate::redirection::RedirectionSpecList;
use crate::signal::{signal_set_handlers_once, Signal};
use crate::terminal::term;
use crate::threads::MainThread;
use crate::topic_monitor::{topic_monitor_principal, GenerationsList, Topic};
use crate::wait_handle::{InternalJobId, WaitHandle, WaitHandleRef, WaitHandleStore};

View File

@@ -28,7 +28,6 @@
has_working_tty_timestamps, shell_modes, str2wcstring, wcs2string, write_loop, ScopeGuard,
ScopeGuarding,
};
use crate::curses::{term, tparm1};
use crate::env::{Environment, TERM_HAS_XN};
use crate::fallback::fish_wcwidth;
use crate::flog::FLOGF;
@@ -37,6 +36,7 @@
use crate::global_safety::RelaxedAtomicBool;
use crate::highlight::{HighlightColorResolver, HighlightSpec};
use crate::output::Outputter;
use crate::terminal::{term, tparm1};
use crate::termsize::{termsize_last, Termsize};
use crate::wchar::prelude::*;
use crate::wcstringutil::string_prefixes_string;
@@ -1409,7 +1409,7 @@ pub struct LayoutCache {
}
// Singleton of the cached escape sequences seen in prompts and similar strings.
// Note this is deliberately exported so that init_curses can clear it.
// Note this is deliberately exported so that init_terminal can clear it.
pub static LAYOUT_CACHE_SHARED: Mutex<LayoutCache> = Mutex::new(LayoutCache::new());
impl LayoutCache {

View File

@@ -25,7 +25,7 @@
pub static TERM: Mutex<Option<Arc<Term>>> = Mutex::new(None);
/// Returns a reference to the global [`Term`] singleton or `None` if not preceded by a successful
/// call to [`curses::setup()`].
/// call to [`terminal::setup()`].
pub fn term() -> Option<Arc<Term>> {
TERM.lock()
.expect("Mutex poisoned!")
@@ -33,7 +33,7 @@ pub fn term() -> Option<Arc<Term>> {
.map(Arc::clone)
}
/// The safe wrapper around curses functionality, initialized by a successful call to [`setup()`]
/// The safe wrapper around terminfo functionality, initialized by a successful call to [`setup()`]
/// and obtained thereafter by calls to [`term()`].
#[allow(dead_code)]
#[derive(Default)]
@@ -183,7 +183,7 @@ pub struct Term {
}
impl Term {
/// Initialize a new `Term` instance, prepopulating the values of all the curses string
/// Initialize a new `Term` instance, prepopulating the values of all the terminfo string
/// capabilities we care about in the process.
fn new(db: terminfo::Database) -> Self {
Term {
@@ -337,13 +337,11 @@ fn new(db: terminfo::Database) -> Self {
/// The `configure` parameter may be set to a callback that takes an `&mut Term` reference to
/// override any capabilities before the `Term` is permanently made immutable.
///
/// Any existing references from `curses::term()` will be invalidated by this call!
/// Any existing references from `terminal::term()` will be invalidated by this call!
pub fn setup<F>(term: Option<&str>, configure: F) -> Option<Arc<Term>>
where
F: Fn(&mut Term),
{
// For now, use the same TERM lock when using `cur_term` to prevent any race conditions in
// curses itself. We might split this to another lock in the future.
let mut global_term = TERM.lock().expect("Mutex poisoned!");
let res = if let Some(term) = term {