mirror of
https://github.com/zellij-org/zellij.git
synced 2024-12-26 10:43:46 +03:00
Warnings purged and some FIXME's addressed
This commit is contained in:
parent
b2720169fb
commit
698bcf83fc
@ -1,17 +1,22 @@
|
|||||||
use crate::pty_bus::PtyInstruction;
|
use crate::pty_bus::PtyInstruction;
|
||||||
use crate::screen::ScreenInstruction;
|
use crate::screen::ScreenInstruction;
|
||||||
use crate::{AppInstruction, SenderWithContext, OPENCALLS};
|
use crate::{AppInstruction, OPENCALLS};
|
||||||
use backtrace::Backtrace;
|
|
||||||
use std::fmt::{Display, Error, Formatter};
|
use std::fmt::{Display, Error, Formatter};
|
||||||
use std::panic::PanicInfo;
|
|
||||||
use std::{process, thread};
|
|
||||||
|
|
||||||
const MAX_THREAD_CALL_STACK: usize = 6;
|
const MAX_THREAD_CALL_STACK: usize = 6;
|
||||||
|
|
||||||
|
#[cfg(not(test))]
|
||||||
|
use crate::SenderWithContext;
|
||||||
|
#[cfg(not(test))]
|
||||||
|
use std::panic::PanicInfo;
|
||||||
|
#[cfg(not(test))]
|
||||||
pub fn handle_panic(
|
pub fn handle_panic(
|
||||||
info: &PanicInfo<'_>,
|
info: &PanicInfo<'_>,
|
||||||
send_app_instructions: &SenderWithContext<AppInstruction>,
|
send_app_instructions: &SenderWithContext<AppInstruction>,
|
||||||
) {
|
) {
|
||||||
|
use backtrace::Backtrace;
|
||||||
|
use std::{process, thread};
|
||||||
let backtrace = Backtrace::new();
|
let backtrace = Backtrace::new();
|
||||||
let thread = thread::current();
|
let thread = thread::current();
|
||||||
let thread = thread.name().unwrap_or("unnamed");
|
let thread = thread.name().unwrap_or("unnamed");
|
||||||
|
@ -91,7 +91,7 @@ fn split_space(
|
|||||||
let mut part_positions = split_space(&part_position_and_size, part);
|
let mut part_positions = split_space(&part_position_and_size, part);
|
||||||
pane_positions.append(&mut part_positions);
|
pane_positions.append(&mut part_positions);
|
||||||
} else {
|
} else {
|
||||||
pane_positions.push((part.clone(), *part_position_and_size)); // FIXME: Probably doesn't need to be cloned
|
pane_positions.push((part.clone(), *part_position_and_size));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pane_positions
|
pane_positions
|
||||||
@ -180,16 +180,6 @@ impl Layout {
|
|||||||
total_panes
|
total_panes
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: I probably shouldn't exist, much less with PathBuf (use &Path)
|
|
||||||
|
|
||||||
pub fn list_plugins(&self) -> Vec<&PathBuf> {
|
|
||||||
let mut plugins: Vec<_> = self.parts.iter().flat_map(Layout::list_plugins).collect();
|
|
||||||
if let Some(path) = &self.plugin {
|
|
||||||
plugins.push(path);
|
|
||||||
}
|
|
||||||
plugins
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn position_panes_in_space(
|
pub fn position_panes_in_space(
|
||||||
&self,
|
&self,
|
||||||
space: &PositionAndSize,
|
space: &PositionAndSize,
|
||||||
|
@ -423,9 +423,6 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: Opt) {
|
|||||||
.recv()
|
.recv()
|
||||||
.expect("failed to receive event on channel");
|
.expect("failed to receive event on channel");
|
||||||
err_ctx.add_call(ContextType::Plugin(PluginContext::from(&event)));
|
err_ctx.add_call(ContextType::Plugin(PluginContext::from(&event)));
|
||||||
// FIXME: Add a line for every other thread that this one calls out to
|
|
||||||
// screen.send_app_instructions.update(err_ctx);
|
|
||||||
// screen.send_pty_instructions.update(err_ctx);
|
|
||||||
match event {
|
match event {
|
||||||
PluginInstruction::Load(pid_tx, path) => {
|
PluginInstruction::Load(pid_tx, path) => {
|
||||||
// FIXME: Cache this compiled module on disk. I could use `(de)serialize_to_file()` for that
|
// FIXME: Cache this compiled module on disk. I could use `(de)serialize_to_file()` for that
|
||||||
|
@ -286,44 +286,6 @@ impl TerminalPane {
|
|||||||
pub fn mark_for_rerender(&mut self) {
|
pub fn mark_for_rerender(&mut self) {
|
||||||
self.should_render = true;
|
self.should_render = true;
|
||||||
}
|
}
|
||||||
// FIXME: Should this be removed?
|
|
||||||
pub fn _handle_event(&mut self, event: VteEvent) {
|
|
||||||
match event {
|
|
||||||
VteEvent::Print(c) => {
|
|
||||||
self.print(c);
|
|
||||||
self.mark_for_rerender();
|
|
||||||
}
|
|
||||||
VteEvent::Execute(byte) => {
|
|
||||||
self.execute(byte);
|
|
||||||
}
|
|
||||||
VteEvent::Hook(params, intermediates, ignore, c) => {
|
|
||||||
self.hook(¶ms, &intermediates, ignore, c);
|
|
||||||
}
|
|
||||||
VteEvent::Put(byte) => {
|
|
||||||
self.put(byte);
|
|
||||||
}
|
|
||||||
VteEvent::Unhook => {
|
|
||||||
self.unhook();
|
|
||||||
}
|
|
||||||
VteEvent::OscDispatch(params, bell_terminated) => {
|
|
||||||
let params: Vec<&[u8]> = params.iter().map(|p| &p[..]).collect();
|
|
||||||
self.osc_dispatch(¶ms[..], bell_terminated);
|
|
||||||
}
|
|
||||||
VteEvent::CsiDispatch(params, intermediates, ignore, c) => {
|
|
||||||
self.csi_dispatch(¶ms, &intermediates, ignore, c);
|
|
||||||
}
|
|
||||||
VteEvent::EscDispatch(intermediates, ignore, byte) => {
|
|
||||||
self.esc_dispatch(&intermediates, ignore, byte);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TODO: merge these two methods
|
|
||||||
pub fn change_size(&mut self, ws: &PositionAndSize) {
|
|
||||||
self.position_and_size.columns = ws.columns;
|
|
||||||
self.position_and_size.rows = ws.rows;
|
|
||||||
self.reflow_lines();
|
|
||||||
self.mark_for_rerender();
|
|
||||||
}
|
|
||||||
pub fn get_x(&self) -> usize {
|
pub fn get_x(&self) -> usize {
|
||||||
match self.position_and_size_override {
|
match self.position_and_size_override {
|
||||||
Some(position_and_size_override) => position_and_size_override.x,
|
Some(position_and_size_override) => position_and_size_override.x,
|
||||||
@ -353,61 +315,15 @@ impl TerminalPane {
|
|||||||
let columns = self.get_columns();
|
let columns = self.get_columns();
|
||||||
self.scroll.change_size(columns, rows);
|
self.scroll.change_size(columns, rows);
|
||||||
}
|
}
|
||||||
pub fn buffer_as_vte_output(&mut self) -> Option<String> {
|
|
||||||
// TODO: rename to render
|
|
||||||
// if self.should_render {
|
|
||||||
if true {
|
|
||||||
// while checking should_render rather than rendering each pane every time
|
|
||||||
// is more performant, it causes some problems when the pane to the left should be
|
|
||||||
// rendered and has wide characters (eg. Chinese characters or emoji)
|
|
||||||
// as a (hopefully) temporary hack, we render all panes until we find a better solution
|
|
||||||
let mut vte_output = String::new();
|
|
||||||
let buffer_lines = &self.read_buffer_as_lines();
|
|
||||||
let display_cols = self.get_columns();
|
|
||||||
let mut character_styles = CharacterStyles::new();
|
|
||||||
for (row, line) in buffer_lines.iter().enumerate() {
|
|
||||||
let x = self.get_x();
|
|
||||||
let y = self.get_y();
|
|
||||||
vte_output = format!("{}\u{1b}[{};{}H\u{1b}[m", vte_output, y + row + 1, x + 1); // goto row/col and reset styles
|
|
||||||
for (col, t_character) in line.iter().enumerate() {
|
|
||||||
if col < display_cols {
|
|
||||||
// in some cases (eg. while resizing) some characters will spill over
|
|
||||||
// before they are corrected by the shell (for the prompt) or by reflowing
|
|
||||||
// lines
|
|
||||||
if let Some(new_styles) =
|
|
||||||
character_styles.update_and_return_diff(&t_character.styles)
|
|
||||||
{
|
|
||||||
// the terminal keeps the previous styles as long as we're in the same
|
|
||||||
// line, so we only want to update the new styles here (this also
|
|
||||||
// includes resetting previous styles as needed)
|
|
||||||
vte_output = format!("{}{}", vte_output, new_styles);
|
|
||||||
}
|
|
||||||
vte_output.push(t_character.character);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
character_styles.clear();
|
|
||||||
}
|
|
||||||
self.mark_for_rerender();
|
|
||||||
Some(vte_output)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn read_buffer_as_lines(&self) -> Vec<Vec<TerminalCharacter>> {
|
pub fn read_buffer_as_lines(&self) -> Vec<Vec<TerminalCharacter>> {
|
||||||
self.scroll.as_character_lines()
|
self.scroll.as_character_lines()
|
||||||
}
|
}
|
||||||
|
#[cfg(test)]
|
||||||
pub fn cursor_coordinates(&self) -> Option<(usize, usize)> {
|
pub fn cursor_coordinates(&self) -> Option<(usize, usize)> {
|
||||||
// (x, y)
|
// (x, y)
|
||||||
self.scroll.cursor_coordinates_on_screen()
|
self.scroll.cursor_coordinates_on_screen()
|
||||||
}
|
}
|
||||||
pub fn scroll_up(&mut self, count: usize) {
|
|
||||||
self.scroll.move_viewport_up(count);
|
|
||||||
self.mark_for_rerender();
|
|
||||||
}
|
|
||||||
pub fn scroll_down(&mut self, count: usize) {
|
|
||||||
self.scroll.move_viewport_down(count);
|
|
||||||
self.mark_for_rerender();
|
|
||||||
}
|
|
||||||
pub fn rotate_scroll_region_up(&mut self, count: usize) {
|
pub fn rotate_scroll_region_up(&mut self, count: usize) {
|
||||||
self.scroll.rotate_scroll_region_up(count);
|
self.scroll.rotate_scroll_region_up(count);
|
||||||
self.mark_for_rerender();
|
self.mark_for_rerender();
|
||||||
@ -416,22 +332,6 @@ impl TerminalPane {
|
|||||||
self.scroll.rotate_scroll_region_down(count);
|
self.scroll.rotate_scroll_region_down(count);
|
||||||
self.mark_for_rerender();
|
self.mark_for_rerender();
|
||||||
}
|
}
|
||||||
pub fn clear_scroll(&mut self) {
|
|
||||||
self.scroll.reset_viewport();
|
|
||||||
self.mark_for_rerender();
|
|
||||||
}
|
|
||||||
pub fn override_size_and_position(&mut self, x: usize, y: usize, size: &PositionAndSize) {
|
|
||||||
let position_and_size_override = PositionAndSize {
|
|
||||||
x,
|
|
||||||
y,
|
|
||||||
rows: size.rows,
|
|
||||||
columns: size.columns,
|
|
||||||
};
|
|
||||||
self.position_and_size_override = Some(position_and_size_override);
|
|
||||||
self.reflow_lines();
|
|
||||||
self.mark_for_rerender();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn add_newline(&mut self) {
|
fn add_newline(&mut self) {
|
||||||
self.scroll.add_canonical_line();
|
self.scroll.add_canonical_line();
|
||||||
// self.reset_all_ansi_codes(); // TODO: find out if we should be resetting here or not
|
// self.reset_all_ansi_codes(); // TODO: find out if we should be resetting here or not
|
||||||
|
@ -2,7 +2,6 @@ use std::{iter, str::from_utf8};
|
|||||||
|
|
||||||
use strip_ansi_escapes::strip;
|
use strip_ansi_escapes::strip;
|
||||||
|
|
||||||
// FIXME: Should this be an extension trait? Or here at all?
|
|
||||||
pub fn ansi_len(s: &str) -> usize {
|
pub fn ansi_len(s: &str) -> usize {
|
||||||
from_utf8(&strip(s.as_bytes()).unwrap())
|
from_utf8(&strip(s.as_bytes()).unwrap())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -8,9 +8,8 @@ use wasmer_wasi::WasiEnv;
|
|||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum PluginInstruction {
|
pub enum PluginInstruction {
|
||||||
Load(Sender<u32>, PathBuf), // FIXME: Maybe send a channel handle?
|
Load(Sender<u32>, PathBuf),
|
||||||
// String buffer, plugin id, rows, cols
|
Draw(Sender<String>, u32, usize, usize), // String buffer, plugin id, rows, cols
|
||||||
Draw(Sender<String>, u32, usize, usize), // FIXME: This is super gross
|
|
||||||
Unload(u32),
|
Unload(u32),
|
||||||
Quit,
|
Quit,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user