Compare commits

...

9 commits

Author SHA1 Message Date
fd89732a72 Translate Alt/Shift/Ctrl-modified keys and F-keys to terminal escape sequences 2026-08-06 08:44:47 +10:00
17c54d8921 Publish the real window-fit grid to the TUI before the first frame 2026-08-06 08:04:26 +10:00
a287ce7281 Retry requesting input focus until the window is focused at startup 2026-08-06 07:27:40 +10:00
edaa1ea8cd Request input focus when the window opens 2026-08-06 07:15:36 +10:00
4690fbbdf1 Start one Ctrl-- notch below the old 32px default font scale 2026-08-05 11:50:21 +10:00
0fc36c2314 Use a 16px default font scale instead of 32px
Cell metrics halve to 8x12px, matching the text size of a typical
terminal at the default 120x30 grid.
2026-08-05 10:44:55 +10:00
613511c275 Bump version to 2026.8.5 2026-08-05 08:37:19 +10:00
47ba62c7b2 Bump version to 2026.8.4 2026-08-04 22:56:28 +10:00
72b9ba94f2 Use a non-sRGB surface format so colors match the terminal
The shader outputs raw sRGB bytes, so an sRGB surface format gamma-encodes
them a second time and everything renders brighter than in a terminal.
Prefer an 8-bit non-sRGB surface format.
2026-08-04 22:53:30 +10:00
5 changed files with 88 additions and 23 deletions

2
Cargo.lock generated
View file

@ -1651,7 +1651,7 @@ dependencies = [
[[package]]
name = "textgrid"
version = "2026.8.3"
version = "2026.8.5"
dependencies = [
"bytemuck",
"glfw",

View file

@ -1,6 +1,6 @@
[package]
name = "textgrid"
version = "2026.8.3"
version = "2026.8.5"
edition = "2021"
[lib]

View file

@ -4,7 +4,7 @@ build-backend = "maturin"
[project]
name = "textgrid"
version = "2026.8.3"
version = "2026.8.5"
requires-python = ">=3.11"
[tool.maturin]

View file

@ -181,7 +181,7 @@ pub fn compute_cell_metrics(font_data: &[u8], scale: f32) -> (u32, u32) {
}
pub fn load_font(font_path: Option<&str>) -> (FontSet, f32) {
let scale = 32.0;
let scale = 32.0 / 1.2;
match font_path {
Some(path) => {
let regular = read_font_data(path);

View file

@ -1,6 +1,7 @@
use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};
use std::sync::mpsc::Receiver;
use std::sync::{Arc, Condvar, Mutex};
use std::time::{Duration, Instant};
use bytemuck::{Pod, Zeroable};
use pyo3::prelude::*;
@ -78,13 +79,24 @@ pub fn start(
w.set_size_polling(true);
w.set_close_polling(true);
w.set_key_polling(true);
w.set_char_polling(true);
w.set_char_mods_polling(true);
w.set_focus_polling(true);
w.focus();
let focus_deadline = Instant::now() + Duration::from_secs(2);
while Instant::now() < focus_deadline && !w.is_focused() {
glfw_ctx.poll_events();
w.focus();
std::thread::sleep(Duration::from_millis(10));
}
let fb = w.get_framebuffer_size();
fb_w = fb.0.max(1) as u32;
fb_h = fb.1.max(1) as u32;
(w, r)
};
cols_atomic.store((fb_w / cell_w).max(1), Ordering::Release);
rows_atomic.store((fb_h / cell_h).max(1), Ordering::Release);
// ----- wgpu -----
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends: {
@ -128,7 +140,9 @@ pub fn start(
.expect("failed to create GPU device");
let caps = surface.get_capabilities(&adapter);
let format = caps.formats[0];
let format = caps.formats.iter().copied()
.find(|f| matches!(f, wgpu::TextureFormat::Bgra8Unorm | wgpu::TextureFormat::Rgba8Unorm))
.unwrap_or(caps.formats[0]);
let mut surface_config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
@ -292,9 +306,12 @@ pub fn start(
});
}
}
glfw::WindowEvent::Char(codepoint) => {
glfw::WindowEvent::CharModifiers(codepoint, mods) => {
if let Some(ref cb) = on_key {
let s: String = codepoint.into();
let mut s: String = codepoint.into();
if mods.contains(glfw::Modifiers::Alt) && !s.is_empty() {
s.insert(0, '\x1b');
}
Python::with_gil(|py| {
let _ = cb.call1(py, (s,));
});
@ -396,26 +413,74 @@ pub fn start(
Some(String::from('\x16'))
}
} else if mods.contains(glfw::Modifiers::Control) {
match key {
glfw::Key::Up => Some("\x1b[1;5A".into()),
glfw::Key::Down => Some("\x1b[1;5B".into()),
glfw::Key::Left => Some("\x1b[1;5D".into()),
glfw::Key::Right => Some("\x1b[1;5C".into()),
_ => {
let code = key as i32;
if (65..=90).contains(&code) {
Some(String::from((code - 64) as u8 as char))
} else {
None
}
}
}
} else {
let mod_num = if mods.contains(glfw::Modifiers::Shift)
&& mods.contains(glfw::Modifiers::Alt)
{ 4 }
else if mods.contains(glfw::Modifiers::Alt) { 3 }
else if mods.contains(glfw::Modifiers::Shift) { 2 }
else { 1 };
match key {
glfw::Key::Up => if mod_num > 1 {
Some(format!("\x1b[1;{}A", mod_num))
} else { Some("\x1b[A".into()) },
glfw::Key::Down => if mod_num > 1 {
Some(format!("\x1b[1;{}B", mod_num))
} else { Some("\x1b[B".into()) },
glfw::Key::Left => if mod_num > 1 {
Some(format!("\x1b[1;{}D", mod_num))
} else { Some("\x1b[D".into()) },
glfw::Key::Right => if mod_num > 1 {
Some(format!("\x1b[1;{}C", mod_num))
} else { Some("\x1b[C".into()) },
glfw::Key::Home => if mod_num > 1 {
Some(format!("\x1b[1;{}H", mod_num))
} else { Some("\x1b[H".into()) },
glfw::Key::End => if mod_num > 1 {
Some(format!("\x1b[1;{}F", mod_num))
} else { Some("\x1b[F".into()) },
glfw::Key::PageUp => if mod_num > 1 {
Some(format!("\x1b[5;{}~", mod_num))
} else { Some("\x1b[5~".into()) },
glfw::Key::PageDown => if mod_num > 1 {
Some(format!("\x1b[6;{}~", mod_num))
} else { Some("\x1b[6~".into()) },
glfw::Key::Tab => if mods.contains(glfw::Modifiers::Shift) {
Some("\x1b[Z".into())
} else { Some("\t".into()) },
glfw::Key::Backspace => if mods.contains(glfw::Modifiers::Alt) {
Some("\x1b\x7f".into())
} else { Some("\x7f".into()) },
glfw::Key::Insert => Some("\x1b[2~".into()),
glfw::Key::Delete => Some("\x1b[3~".into()),
glfw::Key::F1 => Some("\x1bOP".into()),
glfw::Key::F2 => Some("\x1bOQ".into()),
glfw::Key::F3 => Some("\x1bOR".into()),
glfw::Key::F4 => Some("\x1bOS".into()),
glfw::Key::F5 => Some("\x1b[15~".into()),
glfw::Key::F6 => Some("\x1b[17~".into()),
glfw::Key::F7 => Some("\x1b[18~".into()),
glfw::Key::F8 => Some("\x1b[19~".into()),
glfw::Key::F9 => Some("\x1b[20~".into()),
glfw::Key::F10 => Some("\x1b[21~".into()),
glfw::Key::F11 => Some("\x1b[23~".into()),
glfw::Key::F12 => Some("\x1b[24~".into()),
glfw::Key::Enter => Some("\n".into()),
glfw::Key::Escape => Some("\x1b".into()),
glfw::Key::Backspace => Some("\x7f".into()),
glfw::Key::Tab => Some("\t".into()),
glfw::Key::Up => Some("\x1b[A".into()),
glfw::Key::Down => Some("\x1b[B".into()),
glfw::Key::Left => Some("\x1b[D".into()),
glfw::Key::Right => Some("\x1b[C".into()),
glfw::Key::Home => Some("\x1b[H".into()),
glfw::Key::End => Some("\x1b[F".into()),
glfw::Key::PageUp => Some("\x1b[5~".into()),
glfw::Key::PageDown => Some("\x1b[6~".into()),
_ => None,
}
};