mirror of
https://github.com/itsjunetime/tdf.git
synced 2026-08-25 20:54:30 -04:00
Compare commits
2 Commits
main
..
91b923f593
| Author | SHA1 | Date | |
|---|---|---|---|
| 91b923f593 | |||
| d5abc4bae5 |
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
- Added windows support! (thank you to [@jarjk](https://github.com/jarjk) for helping out!)
|
- Added windows support! (thank you to [@jarjk](https://github.com/jarjk) for helping out!)
|
||||||
- Added keybindings (`0`/`$`) to scroll to left or right side of zoomed-in image ([#131](https://github.com/itsjunetime/tdf/pull/131), thank you [@IshDeshpa](https://github.com/IshDeshpa)!)
|
- Added keybindings (`0`/`$`) to scroll to left or right side of zoomed-in image ([#131](https://github.com/itsjunetime/tdf/pull/131), thank you [@IshDeshpa](https://github.com/IshDeshpa)!)
|
||||||
- Added `-t` flag to use terminal foreground/background colors in pdf rendering ([#138](https://github.com/itsjunetime/tdf/pull/138), thank you [@unorsk](https://github.com/unorsk)!
|
|
||||||
- Fixed issue with images clearing/flashing after displaying a certain number on kitty
|
- Fixed issue with images clearing/flashing after displaying a certain number on kitty
|
||||||
- (Internal) decreased runtime footprint of tokio runtime
|
- (Internal) decreased runtime footprint of tokio runtime
|
||||||
|
|
||||||
|
|||||||
Generated
+317
-399
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -31,7 +31,7 @@ tokio = { version = "1.37.0", features = ["rt-multi-thread", "macros"] }
|
|||||||
futures-util = { version = "0.3.30", default-features = false }
|
futures-util = { version = "0.3.30", default-features = false }
|
||||||
flume = { version = "0.12.0", default-features = false, features = ["async"] }
|
flume = { version = "0.12.0", default-features = false, features = ["async"] }
|
||||||
xflags = "0.4.0-pre.2"
|
xflags = "0.4.0-pre.2"
|
||||||
mimalloc = { git = "https://github.com/itsjunetime/mimalloc_rust.git", rev = "1094dbf3afdc0a57215e925a05f2e3160e59575b", features = [ "debug_in_debug" ] }
|
mimalloc = "0.1.43"
|
||||||
nix = { version = "0.31.0", features = ["signal"] }
|
nix = { version = "0.31.0", features = ["signal"] }
|
||||||
mupdf = { git = "https://github.com/messense/mupdf-rs.git", rev = "d7441b9998c92135e329559c0aa71d9dc92cf4de", default-features = false, features = ["svg", "system-fonts", "img"] }
|
mupdf = { git = "https://github.com/messense/mupdf-rs.git", rev = "d7441b9998c92135e329559c0aa71d9dc92cf4de", default-features = false, features = ["svg", "system-fonts", "img"] }
|
||||||
rayon = { version = "1", default-features = false }
|
rayon = { version = "1", default-features = false }
|
||||||
|
|||||||
+1
-1
@@ -72,7 +72,7 @@ pub async fn run_conversion_loop(
|
|||||||
picker: Picker,
|
picker: Picker,
|
||||||
prerender: usize,
|
prerender: usize,
|
||||||
shms_work: bool
|
shms_work: bool
|
||||||
) -> Result<(), Box<SendError<Result<ConvertedPage, RenderError>>>> {
|
) -> Result<(), SendError<Result<ConvertedPage, RenderError>>> {
|
||||||
let mut images = vec![];
|
let mut images = vec![];
|
||||||
let mut page: usize = 0;
|
let mut page: usize = 0;
|
||||||
let pid = std::process::id();
|
let pid = std::process::id();
|
||||||
|
|||||||
+1
-114
@@ -5,7 +5,7 @@ use core::{
|
|||||||
use std::{
|
use std::{
|
||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
ffi::OsString,
|
ffi::OsString,
|
||||||
io::{BufReader, IsTerminal as _, Read as _, Stdout, Write as _, stdout},
|
io::{BufReader, Read as _, Stdout, Write as _, stdout},
|
||||||
mem,
|
mem,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, Mutex},
|
||||||
@@ -116,8 +116,6 @@ async fn inner_main() -> Result<(), WrappedErr> {
|
|||||||
optional -w,--white-color white: String
|
optional -w,--white-color white: String
|
||||||
/// Custom black color, specified in css format (e.g "000000" or "rgb(0, 0, 0)")
|
/// Custom black color, specified in css format (e.g "000000" or "rgb(0, 0, 0)")
|
||||||
optional -b,--black-color black: String
|
optional -b,--black-color black: String
|
||||||
/// Use terminal foreground/background colors for the PDF
|
|
||||||
optional -t,--terminal-colors
|
|
||||||
/// Print the version and exit
|
/// Print the version and exit
|
||||||
optional --version
|
optional --version
|
||||||
/// PDF file to read
|
/// PDF file to read
|
||||||
@@ -139,15 +137,6 @@ async fn inner_main() -> Result<(), WrappedErr> {
|
|||||||
.canonicalize()
|
.canonicalize()
|
||||||
.map_err(|e| WrappedErr(format!("Cannot canonicalize provided file: {e}").into()))?;
|
.map_err(|e| WrappedErr(format!("Cannot canonicalize provided file: {e}").into()))?;
|
||||||
|
|
||||||
if flags.terminal_colors && (flags.black_color.is_some() || flags.white_color.is_some()) {
|
|
||||||
return Err(WrappedErr(
|
|
||||||
"--terminal-colors cannot be combined with --black-color or --white-color".into()
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
let (black, white) = if flags.terminal_colors {
|
|
||||||
query_terminal_colors()
|
|
||||||
} else {
|
|
||||||
let black = flags
|
let black = flags
|
||||||
.black_color
|
.black_color
|
||||||
.as_deref()
|
.as_deref()
|
||||||
@@ -180,9 +169,6 @@ async fn inner_main() -> Result<(), WrappedErr> {
|
|||||||
.transpose()?
|
.transpose()?
|
||||||
.unwrap_or(MUPDF_WHITE);
|
.unwrap_or(MUPDF_WHITE);
|
||||||
|
|
||||||
(black, white)
|
|
||||||
};
|
|
||||||
|
|
||||||
// need to keep it around throughout the lifetime of the program, but don't rly need to use it.
|
// need to keep it around throughout the lifetime of the program, but don't rly need to use it.
|
||||||
// Just need to make sure it doesn't get dropped yet.
|
// Just need to make sure it doesn't get dropped yet.
|
||||||
let maybe_logger = if std::env::var("RUST_LOG").is_ok() {
|
let maybe_logger = if std::env::var("RUST_LOG").is_ok() {
|
||||||
@@ -579,89 +565,6 @@ fn parse_color_to_i32(cs: &str) -> Result<i32, csscolorparser::ParseColorError>
|
|||||||
Ok(i32::from_be_bytes([0, r, g, b]))
|
Ok(i32::from_be_bytes([0, r, g, b]))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn query_terminal_colors() -> (i32, i32) {
|
|
||||||
if !std::io::stdin().is_terminal() || !std::io::stdout().is_terminal() {
|
|
||||||
return (MUPDF_BLACK, MUPDF_WHITE);
|
|
||||||
}
|
|
||||||
|
|
||||||
let Ok(()) = enable_raw_mode() else {
|
|
||||||
return (MUPDF_BLACK, MUPDF_WHITE);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct RawModeGuard;
|
|
||||||
impl Drop for RawModeGuard {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
let _ = disable_raw_mode();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let _guard = RawModeGuard;
|
|
||||||
|
|
||||||
let stdin = std::io::stdin();
|
|
||||||
let mut handle = stdin.lock();
|
|
||||||
|
|
||||||
let fg = query_osc_color(10, &mut handle);
|
|
||||||
let bg = query_osc_color(11, &mut handle);
|
|
||||||
drop(handle);
|
|
||||||
|
|
||||||
(fg.unwrap_or(MUPDF_BLACK), bg.unwrap_or(MUPDF_WHITE))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn query_osc_color(osc: u8, handle: &mut std::io::StdinLock<'_>) -> Option<i32> {
|
|
||||||
print!("\x1b]{osc};?\x1b\\");
|
|
||||||
std::io::stdout().flush().ok()?;
|
|
||||||
|
|
||||||
// response looks like "\u{1b}]10;rgb:rrrr/bbbb/gggg\u{1b}\\" or "\u{1b}]10;rgb:rr/bb/gg\u{1b}\\"
|
|
||||||
// or if osc is 11, "\u{1b}]11;rgb:rrrr/bbbb/gggg\u{1b}\\" or "\u{1b}]11;rgb:rr/bb/gg\u{1b}\\"
|
|
||||||
|
|
||||||
// We expect the response to be either 19 or 25 bytes.
|
|
||||||
let mut response_buf = [0u8; 25];
|
|
||||||
|
|
||||||
handle.read_exact(&mut response_buf[..19])
|
|
||||||
.inspect_err(|e| eprintln!("Couldn't get a response from your terminal for querying OSC {osc}; please file a bug with tdf with your terminal emulator (underlying err: {e})"))
|
|
||||||
.ok()?;
|
|
||||||
|
|
||||||
let two_digit_colors = response_buf[11] == b'/';
|
|
||||||
|
|
||||||
if !two_digit_colors {
|
|
||||||
handle.read_exact(&mut response_buf[19..])
|
|
||||||
.inspect_err(|e| eprintln!("Couldn't get a response from your terminal for querying OSC {osc}; please file a bug with tdf with your terminal emulator (underlying err: {e})"))
|
|
||||||
.ok()?;
|
|
||||||
}
|
|
||||||
|
|
||||||
osc_response_buf_to_color(response_buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn osc_response_buf_to_color(response_buf: [u8; 25]) -> Option<i32> {
|
|
||||||
fn parse(ascii_hex_bytes: &[u8]) -> Option<u8> {
|
|
||||||
let mut color = 0;
|
|
||||||
|
|
||||||
for byte in ascii_hex_bytes {
|
|
||||||
color = (color << 4)
|
|
||||||
+ (match byte {
|
|
||||||
b'0'..=b'9' => byte - b'0',
|
|
||||||
b'A'..=b'F' => byte - (b'A' - 10),
|
|
||||||
b'a'..=b'f' => byte - (b'a' - 10),
|
|
||||||
_ => return None
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Some(color)
|
|
||||||
}
|
|
||||||
|
|
||||||
let two_digit_colors = response_buf[11] == b'/';
|
|
||||||
|
|
||||||
// this is minimimal validation.
|
|
||||||
// the response either has `rrrr/gggg/bbbb` or `rr/gg/bb` starting at byte 9.
|
|
||||||
// So we grab the first two digits out of the r, g, and b sections (since we can only support
|
|
||||||
// 8-bit colors with mupdf; we can't do the 16-bits that the terminal might respond with), we
|
|
||||||
// parse them, and we return it as an i32.
|
|
||||||
let r = parse(&response_buf[9..11])?;
|
|
||||||
let g = parse(&response_buf[if two_digit_colors { 12..14 } else { 14..16 }])?;
|
|
||||||
let b = parse(&response_buf[if two_digit_colors { 15..17 } else { 19..21 }])?;
|
|
||||||
|
|
||||||
Some(i32::from_be_bytes([0, r, g, b]))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_font_size_through_stdio() -> Result<(u16, u16), WrappedErr> {
|
fn get_font_size_through_stdio() -> Result<(u16, u16), WrappedErr> {
|
||||||
// send the command code to get the terminal window size
|
// send the command code to get the terminal window size
|
||||||
print!("\x1b[14t");
|
print!("\x1b[14t");
|
||||||
@@ -728,19 +631,3 @@ fn get_font_size_through_stdio() -> Result<(u16, u16), WrappedErr> {
|
|||||||
|
|
||||||
Ok((w, h))
|
Ok((w, h))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn osc_response_parsing() {
|
|
||||||
fn eq(bytes: [u8; 25], r: u8, g: u8, b: u8) {
|
|
||||||
let resp = osc_response_buf_to_color(bytes);
|
|
||||||
assert_eq!(resp, Some(i32::from_be_bytes([0, r, g, b])));
|
|
||||||
}
|
|
||||||
|
|
||||||
eq(*b"\x1b]10;rgb:11/22/33\x1b\\000000", 0x11, 0x22, 0x33);
|
|
||||||
eq(*b"\x1b]11;rgb:aa11/23bf/fff0\x1b1", 0xaa, 0x23, 0xff);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+8
-8
@@ -738,20 +738,20 @@ impl Tui {
|
|||||||
term.push(c);
|
term.push(c);
|
||||||
InputAction::Redraw.into()
|
InputAction::Redraw.into()
|
||||||
}
|
}
|
||||||
KeyCode::Char(c)
|
|
||||||
if let BottomMessage::Input(InputCommand::GoToPage(_)) =
|
|
||||||
self.bottom_msg && matches!(c, 'g' if self.is_kitty) =>
|
|
||||||
{
|
|
||||||
self.set_msg(MessageSetting::Pop);
|
|
||||||
self.update_zoom(Zoom::pan_bottom)
|
|
||||||
}
|
|
||||||
KeyCode::Char(c)
|
KeyCode::Char(c)
|
||||||
if let BottomMessage::Input(InputCommand::GoToPage(ref mut page)) =
|
if let BottomMessage::Input(InputCommand::GoToPage(ref mut page)) =
|
||||||
self.bottom_msg =>
|
self.bottom_msg && matches!(c, 'g' if self.is_kitty) =>
|
||||||
c.to_digit(10).map(|input_num| {
|
c.to_digit(10).map(|input_num| {
|
||||||
*page = (*page * 10) + input_num as usize;
|
*page = (*page * 10) + input_num as usize;
|
||||||
InputAction::Redraw
|
InputAction::Redraw
|
||||||
}),
|
}),
|
||||||
|
KeyCode::Char(_)
|
||||||
|
if let BottomMessage::Input(InputCommand::GoToPage(_)) =
|
||||||
|
self.bottom_msg =>
|
||||||
|
{
|
||||||
|
self.set_msg(MessageSetting::Pop);
|
||||||
|
self.update_zoom(Zoom::pan_bottom)
|
||||||
|
}
|
||||||
KeyCode::Char(c) => match c {
|
KeyCode::Char(c) => match c {
|
||||||
'l' => self.change_page(PageChange::Next, ChangeAmount::Single),
|
'l' => self.change_page(PageChange::Next, ChangeAmount::Single),
|
||||||
'j' => self.change_page(PageChange::Next, ChangeAmount::WholeScreen),
|
'j' => self.change_page(PageChange::Next, ChangeAmount::WholeScreen),
|
||||||
|
|||||||
Reference in New Issue
Block a user