editors/microsoft-edit: New port, a console text editor written in Rust

This commit is contained in:
MANTANI Nobutaka 2025-05-27 01:58:58 +09:00
parent 66b7b75453
commit 4e186c6810
8 changed files with 784 additions and 0 deletions

View File

@ -205,6 +205,7 @@
SUBDIR += mg
SUBDIR += mickey
SUBDIR += micro
SUBDIR += microsoft-edit
SUBDIR += mined
SUBDIR += mle
SUBDIR += mousepad

View File

@ -0,0 +1,34 @@
PORTNAME= microsoft-edit
DISTVERSIONPREFIX= v
DISTVERSION= 1.0.0
CATEGORIES= editors
MAINTAINER= nobutaka@FreeBSD.org
COMMENT= Console text editor written in Rust
WWW= https://github.com/microsoft/edit
LICENSE= MIT
LICENSE_FILE= ${WRKSRC}/LICENSE
USES= cargo
USE_GITHUB= yes
GH_ACCOUNT= microsoft
GH_PROJECT= edit
BUILD_DEPENDS= rust-nightly>0:lang/rust-nightly
CARGO_BUILDDEP= no
PORTDOCS= CODE_OF_CONDUCT.md CONTRIBUTING.md README.md SECURITY.md
OPTIONS_DEFINE= DOCS
PLIST_FILES= bin/edit bin/msedit
post-install-DOCS-on:
@${MKDIR} ${STAGEDIR}${DOCSDIR}
${INSTALL_DATA} ${PORTDOCS:S|^|${WRKSRC}/|} ${STAGEDIR}${DOCSDIR}
post-install:
${LN} -sf ${PREFIX}/bin/edit ${STAGEDIR}/${PREFIX}/bin/msedit
.include <bsd.port.mk>

View File

@ -0,0 +1,71 @@
CARGO_CRATES= aho-corasick-1.1.3 \
anes-0.1.6 \
anstyle-1.0.10 \
autocfg-1.4.0 \
bumpalo-3.17.0 \
cast-0.3.0 \
cfg-if-1.0.0 \
ciborium-0.2.2 \
ciborium-io-0.2.2 \
ciborium-ll-0.2.2 \
clap-4.5.35 \
clap_builder-4.5.35 \
clap_lex-0.7.4 \
criterion-0.5.1 \
criterion-plot-0.5.0 \
crossbeam-deque-0.8.6 \
crossbeam-epoch-0.9.18 \
crossbeam-utils-0.8.21 \
crunchy-0.2.3 \
either-1.15.0 \
half-2.6.0 \
hermit-abi-0.5.0 \
is-terminal-0.4.16 \
itertools-0.10.5 \
itoa-1.0.15 \
js-sys-0.3.77 \
libc-0.2.171 \
log-0.4.27 \
memchr-2.7.4 \
num-traits-0.2.19 \
once_cell-1.21.3 \
oorandom-11.1.5 \
plotters-0.3.7 \
plotters-backend-0.3.7 \
plotters-svg-0.3.7 \
proc-macro2-1.0.94 \
quote-1.0.40 \
rayon-1.10.0 \
rayon-core-1.12.1 \
regex-1.11.1 \
regex-automata-0.4.9 \
regex-syntax-0.8.5 \
rustversion-1.0.20 \
ryu-1.0.20 \
same-file-1.0.6 \
serde-1.0.219 \
serde_derive-1.0.219 \
serde_json-1.0.140 \
syn-2.0.100 \
tinytemplate-1.2.1 \
toml-0.5.11 \
unicode-ident-1.0.18 \
walkdir-2.5.0 \
wasm-bindgen-0.2.100 \
wasm-bindgen-backend-0.2.100 \
wasm-bindgen-macro-0.2.100 \
wasm-bindgen-macro-support-0.2.100 \
wasm-bindgen-shared-0.2.100 \
web-sys-0.3.77 \
winapi-util-0.1.9 \
windows-sys-0.59.0 \
windows-targets-0.52.6 \
windows_aarch64_gnullvm-0.52.6 \
windows_aarch64_msvc-0.52.6 \
windows_i686_gnu-0.52.6 \
windows_i686_gnullvm-0.52.6 \
windows_i686_msvc-0.52.6 \
windows_x86_64_gnu-0.52.6 \
windows_x86_64_gnullvm-0.52.6 \
windows_x86_64_msvc-0.52.6 \
winres-0.1.12

View File

@ -0,0 +1,145 @@
TIMESTAMP = 1748176479
SHA256 (rust/crates/aho-corasick-1.1.3.crate) = 8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916
SIZE (rust/crates/aho-corasick-1.1.3.crate) = 183311
SHA256 (rust/crates/anes-0.1.6.crate) = 4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299
SIZE (rust/crates/anes-0.1.6.crate) = 23857
SHA256 (rust/crates/anstyle-1.0.10.crate) = 55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9
SIZE (rust/crates/anstyle-1.0.10.crate) = 15725
SHA256 (rust/crates/autocfg-1.4.0.crate) = ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26
SIZE (rust/crates/autocfg-1.4.0.crate) = 17712
SHA256 (rust/crates/bumpalo-3.17.0.crate) = 1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf
SIZE (rust/crates/bumpalo-3.17.0.crate) = 91975
SHA256 (rust/crates/cast-0.3.0.crate) = 37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5
SIZE (rust/crates/cast-0.3.0.crate) = 11452
SHA256 (rust/crates/cfg-if-1.0.0.crate) = baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd
SIZE (rust/crates/cfg-if-1.0.0.crate) = 7934
SHA256 (rust/crates/ciborium-0.2.2.crate) = 42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e
SIZE (rust/crates/ciborium-0.2.2.crate) = 35611
SHA256 (rust/crates/ciborium-io-0.2.2.crate) = 05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757
SIZE (rust/crates/ciborium-io-0.2.2.crate) = 6697
SHA256 (rust/crates/ciborium-ll-0.2.2.crate) = 57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9
SIZE (rust/crates/ciborium-ll-0.2.2.crate) = 14695
SHA256 (rust/crates/clap-4.5.35.crate) = d8aa86934b44c19c50f87cc2790e19f54f7a67aedb64101c2e1a2e5ecfb73944
SIZE (rust/crates/clap-4.5.35.crate) = 56970
SHA256 (rust/crates/clap_builder-4.5.35.crate) = 2414dbb2dd0695280da6ea9261e327479e9d37b0630f6b53ba2a11c60c679fd9
SIZE (rust/crates/clap_builder-4.5.35.crate) = 168525
SHA256 (rust/crates/clap_lex-0.7.4.crate) = f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6
SIZE (rust/crates/clap_lex-0.7.4.crate) = 12858
SHA256 (rust/crates/criterion-0.5.1.crate) = f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f
SIZE (rust/crates/criterion-0.5.1.crate) = 110088
SHA256 (rust/crates/criterion-plot-0.5.0.crate) = 6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1
SIZE (rust/crates/criterion-plot-0.5.0.crate) = 22706
SHA256 (rust/crates/crossbeam-deque-0.8.6.crate) = 9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51
SIZE (rust/crates/crossbeam-deque-0.8.6.crate) = 22471
SHA256 (rust/crates/crossbeam-epoch-0.9.18.crate) = 5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e
SIZE (rust/crates/crossbeam-epoch-0.9.18.crate) = 46875
SHA256 (rust/crates/crossbeam-utils-0.8.21.crate) = d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28
SIZE (rust/crates/crossbeam-utils-0.8.21.crate) = 42691
SHA256 (rust/crates/crunchy-0.2.3.crate) = 43da5946c66ffcc7745f48db692ffbb10a83bfe0afd96235c5c2a4fb23994929
SIZE (rust/crates/crunchy-0.2.3.crate) = 3775
SHA256 (rust/crates/either-1.15.0.crate) = 48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719
SIZE (rust/crates/either-1.15.0.crate) = 20114
SHA256 (rust/crates/half-2.6.0.crate) = 459196ed295495a68f7d7fe1d84f6c4b7ff0e21fe3017b2f283c6fac3ad803c9
SIZE (rust/crates/half-2.6.0.crate) = 59507
SHA256 (rust/crates/hermit-abi-0.5.0.crate) = fbd780fe5cc30f81464441920d82ac8740e2e46b29a6fad543ddd075229ce37e
SIZE (rust/crates/hermit-abi-0.5.0.crate) = 17480
SHA256 (rust/crates/is-terminal-0.4.16.crate) = e04d7f318608d35d4b61ddd75cbdaee86b023ebe2bd5a66ee0915f0bf93095a9
SIZE (rust/crates/is-terminal-0.4.16.crate) = 7811
SHA256 (rust/crates/itertools-0.10.5.crate) = b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473
SIZE (rust/crates/itertools-0.10.5.crate) = 115354
SHA256 (rust/crates/itoa-1.0.15.crate) = 4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c
SIZE (rust/crates/itoa-1.0.15.crate) = 11231
SHA256 (rust/crates/js-sys-0.3.77.crate) = 1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f
SIZE (rust/crates/js-sys-0.3.77.crate) = 55538
SHA256 (rust/crates/libc-0.2.171.crate) = c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6
SIZE (rust/crates/libc-0.2.171.crate) = 785246
SHA256 (rust/crates/log-0.4.27.crate) = 13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94
SIZE (rust/crates/log-0.4.27.crate) = 48120
SHA256 (rust/crates/memchr-2.7.4.crate) = 78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3
SIZE (rust/crates/memchr-2.7.4.crate) = 96670
SHA256 (rust/crates/num-traits-0.2.19.crate) = 071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841
SIZE (rust/crates/num-traits-0.2.19.crate) = 51631
SHA256 (rust/crates/once_cell-1.21.3.crate) = 42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d
SIZE (rust/crates/once_cell-1.21.3.crate) = 34534
SHA256 (rust/crates/oorandom-11.1.5.crate) = d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e
SIZE (rust/crates/oorandom-11.1.5.crate) = 23750
SHA256 (rust/crates/plotters-0.3.7.crate) = 5aeb6f403d7a4911efb1e33402027fc44f29b5bf6def3effcc22d7bb75f2b747
SIZE (rust/crates/plotters-0.3.7.crate) = 149031
SHA256 (rust/crates/plotters-backend-0.3.7.crate) = df42e13c12958a16b3f7f4386b9ab1f3e7933914ecea48da7139435263a4172a
SIZE (rust/crates/plotters-backend-0.3.7.crate) = 13709
SHA256 (rust/crates/plotters-svg-0.3.7.crate) = 51bae2ac328883f7acdfea3d66a7c35751187f870bc81f94563733a154d7a670
SIZE (rust/crates/plotters-svg-0.3.7.crate) = 6715
SHA256 (rust/crates/proc-macro2-1.0.94.crate) = a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84
SIZE (rust/crates/proc-macro2-1.0.94.crate) = 52391
SHA256 (rust/crates/quote-1.0.40.crate) = 1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d
SIZE (rust/crates/quote-1.0.40.crate) = 31063
SHA256 (rust/crates/rayon-1.10.0.crate) = b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa
SIZE (rust/crates/rayon-1.10.0.crate) = 180155
SHA256 (rust/crates/rayon-core-1.12.1.crate) = 1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2
SIZE (rust/crates/rayon-core-1.12.1.crate) = 70701
SHA256 (rust/crates/regex-1.11.1.crate) = b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191
SIZE (rust/crates/regex-1.11.1.crate) = 254170
SHA256 (rust/crates/regex-automata-0.4.9.crate) = 809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908
SIZE (rust/crates/regex-automata-0.4.9.crate) = 618525
SHA256 (rust/crates/regex-syntax-0.8.5.crate) = 2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c
SIZE (rust/crates/regex-syntax-0.8.5.crate) = 357541
SHA256 (rust/crates/rustversion-1.0.20.crate) = eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2
SIZE (rust/crates/rustversion-1.0.20.crate) = 20666
SHA256 (rust/crates/ryu-1.0.20.crate) = 28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f
SIZE (rust/crates/ryu-1.0.20.crate) = 48738
SHA256 (rust/crates/same-file-1.0.6.crate) = 93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502
SIZE (rust/crates/same-file-1.0.6.crate) = 10183
SHA256 (rust/crates/serde-1.0.219.crate) = 5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6
SIZE (rust/crates/serde-1.0.219.crate) = 78983
SHA256 (rust/crates/serde_derive-1.0.219.crate) = 5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00
SIZE (rust/crates/serde_derive-1.0.219.crate) = 57798
SHA256 (rust/crates/serde_json-1.0.140.crate) = 20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373
SIZE (rust/crates/serde_json-1.0.140.crate) = 154852
SHA256 (rust/crates/syn-2.0.100.crate) = b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0
SIZE (rust/crates/syn-2.0.100.crate) = 297947
SHA256 (rust/crates/tinytemplate-1.2.1.crate) = be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc
SIZE (rust/crates/tinytemplate-1.2.1.crate) = 26490
SHA256 (rust/crates/toml-0.5.11.crate) = f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234
SIZE (rust/crates/toml-0.5.11.crate) = 54910
SHA256 (rust/crates/unicode-ident-1.0.18.crate) = 5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512
SIZE (rust/crates/unicode-ident-1.0.18.crate) = 47743
SHA256 (rust/crates/walkdir-2.5.0.crate) = 29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b
SIZE (rust/crates/walkdir-2.5.0.crate) = 23951
SHA256 (rust/crates/wasm-bindgen-0.2.100.crate) = 1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5
SIZE (rust/crates/wasm-bindgen-0.2.100.crate) = 48288
SHA256 (rust/crates/wasm-bindgen-backend-0.2.100.crate) = 2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6
SIZE (rust/crates/wasm-bindgen-backend-0.2.100.crate) = 32111
SHA256 (rust/crates/wasm-bindgen-macro-0.2.100.crate) = 7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407
SIZE (rust/crates/wasm-bindgen-macro-0.2.100.crate) = 9663
SHA256 (rust/crates/wasm-bindgen-macro-support-0.2.100.crate) = 8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de
SIZE (rust/crates/wasm-bindgen-macro-support-0.2.100.crate) = 26243
SHA256 (rust/crates/wasm-bindgen-shared-0.2.100.crate) = 1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d
SIZE (rust/crates/wasm-bindgen-shared-0.2.100.crate) = 8570
SHA256 (rust/crates/web-sys-0.3.77.crate) = 33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2
SIZE (rust/crates/web-sys-0.3.77.crate) = 638246
SHA256 (rust/crates/winapi-util-0.1.9.crate) = cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb
SIZE (rust/crates/winapi-util-0.1.9.crate) = 12464
SHA256 (rust/crates/windows-sys-0.59.0.crate) = 1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b
SIZE (rust/crates/windows-sys-0.59.0.crate) = 2387323
SHA256 (rust/crates/windows-targets-0.52.6.crate) = 9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973
SIZE (rust/crates/windows-targets-0.52.6.crate) = 6403
SHA256 (rust/crates/windows_aarch64_gnullvm-0.52.6.crate) = 32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3
SIZE (rust/crates/windows_aarch64_gnullvm-0.52.6.crate) = 435718
SHA256 (rust/crates/windows_aarch64_msvc-0.52.6.crate) = 09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469
SIZE (rust/crates/windows_aarch64_msvc-0.52.6.crate) = 832615
SHA256 (rust/crates/windows_i686_gnu-0.52.6.crate) = 8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b
SIZE (rust/crates/windows_i686_gnu-0.52.6.crate) = 880402
SHA256 (rust/crates/windows_i686_gnullvm-0.52.6.crate) = 0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66
SIZE (rust/crates/windows_i686_gnullvm-0.52.6.crate) = 475940
SHA256 (rust/crates/windows_i686_msvc-0.52.6.crate) = 240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66
SIZE (rust/crates/windows_i686_msvc-0.52.6.crate) = 901163
SHA256 (rust/crates/windows_x86_64_gnu-0.52.6.crate) = 147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78
SIZE (rust/crates/windows_x86_64_gnu-0.52.6.crate) = 836363
SHA256 (rust/crates/windows_x86_64_gnullvm-0.52.6.crate) = 24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d
SIZE (rust/crates/windows_x86_64_gnullvm-0.52.6.crate) = 435707
SHA256 (rust/crates/windows_x86_64_msvc-0.52.6.crate) = 589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec
SIZE (rust/crates/windows_x86_64_msvc-0.52.6.crate) = 832564
SHA256 (rust/crates/winres-0.1.12.crate) = b68db261ef59e9e52806f688020631e987592bd83619edccda9c47d42cde4f6c
SIZE (rust/crates/winres-0.1.12.crate) = 19772
SHA256 (microsoft-edit-v1.0.0_GH0.tar.gz) = 6718d9a96aa9dd2117d9d4afa83b0278ef007bcd42bdb1e8c4e2ad34144246c0
SIZE (microsoft-edit-v1.0.0_GH0.tar.gz) = 250150

View File

@ -0,0 +1,10 @@
--- src/lib.rs.orig 2025-05-18 18:11:22 UTC
+++ src/lib.rs
@@ -5,7 +5,6 @@
allocator_api,
breakpoint,
cold_path,
- inherent_str_constructors,
let_chains,
linked_list_cursors,
maybe_uninit_fill,

View File

@ -0,0 +1,97 @@
--- src/sys/unix.rs.orig 2025-05-18 18:11:22 UTC
+++ src/sys/unix.rs
@@ -8,9 +8,9 @@ use std::fs::{self, File};
use std::ffi::{CStr, c_int, c_void};
use std::fs::{self, File};
-use std::mem::{self, MaybeUninit};
+use std::mem::{self, ManuallyDrop, MaybeUninit};
use std::os::fd::{AsRawFd as _, FromRawFd as _};
-use std::ptr::{self, NonNull, null, null_mut};
+use std::ptr::{self, NonNull, null_mut};
use std::{thread, time};
use crate::arena::{Arena, ArenaString, scratch_arena};
@@ -195,11 +195,19 @@ pub fn read_stdin(arena: &Arena, mut timeout: time::Du
let beg = time::Instant::now();
let mut pollfd = libc::pollfd { fd: STATE.stdin, events: libc::POLLIN, revents: 0 };
- let ts = libc::timespec {
- tv_sec: timeout.as_secs() as libc::time_t,
- tv_nsec: timeout.subsec_nanos() as libc::c_long,
- };
- let ret = libc::ppoll(&mut pollfd, 1, &ts, null());
+ let ret;
+ #[cfg(target_os = "linux")]
+ {
+ let ts = libc::timespec {
+ tv_sec: timeout.as_secs() as libc::time_t,
+ tv_nsec: timeout.subsec_nanos() as libc::c_long,
+ };
+ ret = libc::ppoll(&mut pollfd, 1, &ts, ptr::null());
+ }
+ #[cfg(not(target_os = "linux"))]
+ {
+ ret = libc::poll(&mut pollfd, 1, timeout.as_millis() as libc::c_int);
+ }
if ret < 0 {
return None; // Error? Let's assume it's an EOF.
}
@@ -225,7 +233,7 @@ pub fn read_stdin(arena: &Arena, mut timeout: time::Du
return None; // EOF
}
if ret < 0 {
- match *libc::__errno_location() {
+ match errno() {
libc::EINTR if STATE.inject_resize => break,
libc::EAGAIN if timeout == time::Duration::ZERO => break,
libc::EINTR | libc::EAGAIN => {}
@@ -304,7 +312,7 @@ pub fn write_stdout(text: &str) {
continue;
}
- let err = unsafe { *libc::__errno_location() };
+ let err = errno();
if err != libc::EINTR {
return;
}
@@ -407,7 +415,7 @@ unsafe fn load_library(name: &CStr) -> apperr::Result<
unsafe fn load_library(name: &CStr) -> apperr::Result<NonNull<c_void>> {
unsafe {
NonNull::new(libc::dlopen(name.as_ptr(), libc::RTLD_LAZY))
- .ok_or_else(|| errno_to_apperr(libc::ELIBACC))
+ .ok_or_else(|| errno_to_apperr(libc::ENOENT))
}
}
@@ -423,7 +431,7 @@ pub unsafe fn get_proc_address<T>(handle: NonNull<c_vo
unsafe {
let sym = libc::dlsym(handle.as_ptr(), name.as_ptr());
if sym.is_null() {
- Err(errno_to_apperr(libc::ELIBACC))
+ Err(errno_to_apperr(libc::ENOENT))
} else {
Ok(mem::transmute_copy(&sym))
}
@@ -538,6 +546,14 @@ pub fn preferred_languages(arena: &Arena) -> Vec<Arena
}
#[inline]
+fn errno() -> i32 {
+ // Under `-O -Copt-level=s` the 1.87 compiler fails to fully inline and
+ // remove the raw_os_error() call. This leaves us with the drop() call.
+ // ManuallyDrop fixes that and results in a direct `std::sys::os::errno` call.
+ ManuallyDrop::new(std::io::Error::last_os_error()).raw_os_error().unwrap_or(0)
+}
+
+#[inline]
pub(crate) fn io_error_to_apperr(err: std::io::Error) -> apperr::Error {
errno_to_apperr(err.raw_os_error().unwrap_or(0))
}
@@ -565,5 +581,5 @@ fn check_int_return(ret: libc::c_int) -> apperr::Resul
}
fn check_int_return(ret: libc::c_int) -> apperr::Result<libc::c_int> {
- if ret < 0 { Err(errno_to_apperr(unsafe { *libc::__errno_location() })) } else { Ok(ret) }
+ if ret < 0 { Err(errno_to_apperr(errno())) } else { Ok(ret) }
}

View File

@ -0,0 +1,421 @@
--- src/tui.rs.orig 2025-05-18 18:11:22 UTC
+++ src/tui.rs
@@ -640,6 +640,7 @@ impl Tui {
tree,
last_modal: None,
+ focused_node: None,
next_block_id_mixin: 0,
needs_settling: false,
@@ -653,6 +654,9 @@ impl Tui {
// out where is to do a binary search of commenting out code in main.rs.
debug_assert!(ctx.tree.current_node.borrow().stack_parent.is_none());
+ // End the root node.
+ ctx.block_end();
+
// Ensure that focus doesn't escape the active modal.
if let Some(node) = ctx.last_modal
&& !self.is_subtree_focused(&node.borrow())
@@ -684,18 +688,8 @@ impl Tui {
// Remove any unknown nodes from the focus path.
// It's important that we do this after the tree has been swapped out,
// so that pop_focusable_node() has access to the newest version of the tree.
- let focus_path_changed = self.pop_focusable_node(focus_path_pop_min);
- needs_settling |= focus_path_changed;
+ needs_settling |= self.pop_focusable_node(focus_path_pop_min);
- // If some elements went away and the focus path changed above, we ignore tab presses.
- // It may otherwise lead to weird situations where focus moves unexpectedly.
- if !focus_path_changed
- && !ctx.input_consumed
- && let Some(input) = ctx.input_keyboard
- {
- needs_settling |= self.move_focus(input);
- }
-
// `needs_more_settling()` depends on the current value
// of `settling_have` and so we increment it first.
self.settling_have += 1;
@@ -1213,117 +1207,6 @@ impl Tui {
last_before != last_after
}
- // TODO: Move this into `block_end()` and run it whenever the block is a `focus_well`.
- // It makes no sense otherwise that all input handling occurs in the controls, except for this.
- fn move_focus(&mut self, input: InputKey) -> bool {
- if !matches!(input, vk::TAB | SHIFT_TAB | vk::UP | vk::DOWN | vk::LEFT | vk::RIGHT) {
- return false;
- }
-
- let focused_id = self.focused_node_path.last().cloned().unwrap_or(0);
- let Some(focused) = self.prev_node_map.get(focused_id) else {
- debug_assert!(false); // The caller should've cleaned up the focus path.
- return false;
- };
-
- let mut focused_start = focused;
- let mut root = focused;
-
- // Figure out if we're inside a focus void (a container that doesn't
- // allow tabbing inside), and in that case, toss the focus to it.
- //
- // Also, figure out the container within which the focus must be contained.
- // This way, tab/shift-tab only moves within the same window.
- // The ROOT_ID node has no parent, and the others have a float attribute.
- // If the root is the focused node, it should of course not move upward.
- loop {
- let root_node = root.borrow();
- if root_node.attributes.focus_well {
- break;
- }
- if root_node.attributes.focus_void {
- focused_start = root;
- }
- root = match root_node.parent {
- Some(parent) => parent,
- None => break,
- }
- }
-
- let forward;
- let min_depth;
- match input {
- SHIFT_TAB | vk::TAB => {
- forward = input == vk::TAB;
- min_depth = usize::MAX;
- }
- vk::UP | vk::DOWN => {
- forward = input == vk::DOWN;
- min_depth = usize::MAX;
- }
- vk::LEFT | vk::RIGHT => {
- // Find the cell within a row within a table that we're in.
- // To do so we'll use a circular buffer of the last 3 nodes while we travel up.
- let mut buf = [None; 3];
- let mut idx = buf.len() - 1;
- let mut node = focused_start;
-
- loop {
- idx = (idx + 1) % buf.len();
- buf[idx] = Some(node);
- if let NodeContent::Table(..) = &node.borrow().content {
- break;
- }
- if ptr::eq(node, root) {
- return false;
- }
- node = match node.borrow().parent {
- Some(parent) => parent,
- None => return false,
- }
- }
-
- // The current `idx` points to the table.
- // The last item is the row.
- // The 2nd to last item is the cell.
- let Some(row) = buf[(idx + 3 - 1) % buf.len()] else {
- return false;
- };
- let Some(cell) = buf[(idx + 3 - 2) % buf.len()] else {
- return false;
- };
-
- root = row;
- focused_start = cell;
- forward = input == vk::RIGHT;
- min_depth = root.borrow().depth;
- }
- _ => return false,
- }
-
- let mut focused_next = focused_start;
- Tree::visit_all(root, focused_start, forward, |node| {
- let n = node.borrow();
- if ptr::eq(node, root) {
- VisitControl::Continue
- } else if n.attributes.focusable && !ptr::eq(node, focused_start) {
- focused_next = node;
- VisitControl::Stop
- } else if n.attributes.focus_void || n.depth >= min_depth {
- VisitControl::SkipChildren
- } else {
- VisitControl::Continue
- }
- });
-
- if ptr::eq(focused_next, focused_start) {
- false
- } else {
- Tui::build_node_path(Some(focused_next), &mut self.focused_node_path);
- true
- }
- }
-
// Scroll the focused node(s) into view inside scrollviews
fn scroll_to_focused(&mut self) -> bool {
let focused_id = self.focused_node_path.last().cloned().unwrap_or(0);
@@ -1375,6 +1258,7 @@ pub struct Context<'a, 'input> {
tree: Tree<'a>,
last_modal: Option<&'a NodeCell<'a>>,
+ focused_node: Option<&'a NodeCell<'a>>,
next_block_id_mixin: u64,
needs_settling: bool,
@@ -1484,8 +1368,83 @@ impl<'a> Context<'a, '_> {
/// Ends the current UI block, returning to its parent container.
pub fn block_end(&mut self) {
self.tree.pop_stack();
+ self.block_end_move_focus();
}
+ fn block_end_move_focus(&mut self) {
+ // At this point, it's more like "focus_well?" instead of "focus_well!".
+ let focus_well = self.tree.last_node;
+
+ // Remember the focused node, if any, because once the code below runs,
+ // we need it for the `Tree::visit_all` call.
+ if self.is_focused() {
+ self.focused_node = Some(focus_well);
+ }
+
+ // Filter down to nodes that are focus wells and contain the focus.
+ // They're basically the "tab container".
+ if !focus_well.borrow().attributes.focus_well {
+ return;
+ }
+
+ // The mere fact that there's a `focused_node` indicates that we're the
+ // first `block_end()` call that's a focus well and also contains the focus.
+ let Some(focused) = self.focused_node else {
+ return;
+ };
+
+ // Filter down to Tab/Shift+Tab inputs.
+ if self.input_consumed {
+ return;
+ }
+ let Some(input) = self.input_keyboard else {
+ return;
+ };
+ if !matches!(input, SHIFT_TAB | vk::TAB) {
+ return;
+ }
+
+ let forward = input == vk::TAB;
+ let mut focused_start = focused;
+ let mut focused_next = focused;
+
+ // We may be in a focus void right now (= doesn't want to be tabbed into),
+ // so first we must go up the tree until we're outside of it.
+ loop {
+ if ptr::eq(focused_start, focus_well) {
+ // If we hit the root / focus well, we weren't in a focus void,
+ // and can reset `focused_before` to the current focused node.
+ focused_start = focused;
+ break;
+ }
+
+ focused_start = focused_start.borrow().parent.unwrap();
+ if focused_start.borrow().attributes.focus_void {
+ break;
+ }
+ }
+
+ Tree::visit_all(focus_well, focused_start, forward, |node| {
+ let n = node.borrow();
+ if n.attributes.focusable && !ptr::eq(node, focused_start) {
+ focused_next = node;
+ VisitControl::Stop
+ } else if n.attributes.focus_void {
+ VisitControl::SkipChildren
+ } else {
+ VisitControl::Continue
+ }
+ });
+
+ if ptr::eq(focused_next, focused_start) {
+ return;
+ }
+
+ Tui::build_node_path(Some(focused_next), &mut self.tui.focused_node_path);
+ self.set_input_consumed();
+ self.needs_rerender();
+ }
+
/// Mixes in an extra value to the next UI block's ID for uniqueness.
/// Use this when you build a list of items with the same classname.
pub fn next_block_id_mixin(&mut self, id: u64) {
@@ -1796,6 +1755,8 @@ impl<'a> Context<'a, '_> {
debug_assert!(matches!(parent.content, NodeContent::Table(_)));
self.block_end();
+ self.table_end_row();
+
self.next_block_id_mixin(parent.child_count as u64);
}
}
@@ -1803,6 +1764,10 @@ impl<'a> Context<'a, '_> {
self.block_begin("row");
}
+ fn table_end_row(&mut self) {
+ self.table_row_move_focus();
+ }
+
/// Ends the current table block.
pub fn table_end(&mut self) {
let current_node = self.tree.current_node.borrow();
@@ -1811,11 +1776,136 @@ impl<'a> Context<'a, '_> {
// current_node will refer to the table. Otherwise, it'll refer to the current row.
if !matches!(current_node.content, NodeContent::Table(_)) {
self.block_end();
+ self.table_end_row();
}
self.block_end(); // table
+ self.table_end_move_focus();
}
+ fn table_row_move_focus(&mut self) {
+ // Filter down to table rows that are focused.
+ if !self.contains_focus() {
+ return;
+ }
+
+ // Filter down to left/right inputs.
+ if self.input_consumed {
+ return;
+ }
+ let Some(input) = self.input_keyboard else {
+ return;
+ };
+ if !matches!(input, vk::LEFT | vk::RIGHT) {
+ return;
+ }
+
+ let row = self.tree.last_node;
+ let Some(&focused_cell_id) = self.tui.focused_node_path.get(row.borrow().depth + 1) else {
+ return;
+ };
+
+ let mut prev_next = NodeSiblings { prev: None, next: None };
+ let mut focused = None;
+
+ // Iterate through the cells in the row, looking for the focused cell.
+ // Take note of the previous and next focusable cells around the focused one.
+ for cell in Tree::iterate_siblings(row.borrow().children.first) {
+ let n = cell.borrow();
+ if n.id == focused_cell_id {
+ focused = Some(cell);
+ } else if n.attributes.focusable {
+ if focused.is_none() {
+ prev_next.prev = Some(cell);
+ } else {
+ prev_next.next = Some(cell);
+ break;
+ }
+ }
+ }
+
+ if focused.is_none() {
+ return;
+ }
+
+ let forward = input == vk::RIGHT;
+ let children_idx = if forward { NodeChildren::FIRST } else { NodeChildren::LAST };
+ let siblings_idx = if forward { NodeSiblings::NEXT } else { NodeSiblings::PREV };
+ let Some(focused_next) =
+ prev_next.get(siblings_idx).or_else(|| row.borrow().children.get(children_idx))
+ else {
+ return;
+ };
+
+ Tui::build_node_path(Some(focused_next), &mut self.tui.focused_node_path);
+ self.set_input_consumed();
+ self.needs_rerender();
+ }
+
+ fn table_end_move_focus(&mut self) {
+ // Filter down to table rows that are focused.
+ if !self.contains_focus() {
+ return;
+ }
+
+ // Filter down to up/down inputs.
+ if self.input_consumed {
+ return;
+ }
+ let Some(input) = self.input_keyboard else {
+ return;
+ };
+ if !matches!(input, vk::UP | vk::DOWN) {
+ return;
+ }
+
+ let table = self.tree.last_node;
+ if table.borrow().child_count <= 1 {
+ // If there's just one row, we can't move focus up or down.
+ return;
+ }
+
+ let Some(&focused_row_id) = self.tui.focused_node_path.get(table.borrow().depth + 1) else {
+ return;
+ };
+
+ let mut prev_next = NodeSiblings { prev: None, next: None };
+ let mut focused = None;
+
+ // Iterate through the row in the table, looking for the focused row.
+ // Take note of the previous and next focusable rows around the focused one.
+ for cell in Tree::iterate_siblings(table.borrow().children.first) {
+ let n = cell.borrow();
+ if n.id == focused_row_id {
+ focused = Some(cell);
+ } else if n.attributes.focusable {
+ if focused.is_none() {
+ prev_next.prev = Some(cell);
+ } else {
+ prev_next.next = Some(cell);
+ break;
+ }
+ }
+ }
+
+ if focused.is_none() {
+ return;
+ }
+
+ let forward = input == vk::DOWN;
+ let children_idx = if forward { NodeChildren::FIRST } else { NodeChildren::LAST };
+ let siblings_idx = if forward { NodeSiblings::NEXT } else { NodeSiblings::PREV };
+ let Some(focused_next) =
+ prev_next.get(siblings_idx).or_else(|| table.borrow().children.get(children_idx))
+ else {
+ return;
+ };
+
+ Tui::build_node_path(Some(focused_next), &mut self.tui.focused_node_path);
+ self.set_input_consumed();
+ self.needs_rerender();
+ }
+
/// Creates a simple text label.
pub fn label(&mut self, classname: &'static str, text: &str) {
self.styled_label_begin(classname);
@@ -3312,9 +3402,10 @@ impl<'a> Tree<'a> {
/// Completes the current node and moves focus to the parent.
fn pop_stack(&mut self) {
let current_node = self.current_node.borrow();
- let stack_parent = current_node.stack_parent.unwrap();
- self.last_node = self.current_node;
- self.current_node = stack_parent;
+ if let Some(stack_parent) = current_node.stack_parent {
+ self.last_node = self.current_node;
+ self.current_node = stack_parent;
+ }
}
fn iterate_siblings(

View File

@ -0,0 +1,5 @@
Microsoft Edit pays homage to the classic MS-DOS Editor, but with a modern
interface and input controls similar to VS Code.
The goal is to provide an accessible editor that even users largely
unfamiliar with terminals can easily use.