42 Commits

Author SHA1 Message Date
623c2f5f29 docs: Removed completed TODOs. 2026-06-15 19:34:59 -04:00
5ea760a7fa test: Table tests now view full output. 2026-06-15 19:28:56 -04:00
c5d578dd1b test: commands now accept stdout/stderr fields. 2026-06-15 19:26:44 -04:00
a4417affa1 chore: Cleaned up code. 2026-06-15 16:45:36 -04:00
b47ca8f14d feat: Config can be loaded from any path with --config-file (-c) flag. 2026-06-15 09:00:16 -04:00
e6f09a037b test: Added missing tests. 2026-06-15 08:00:11 -04:00
46c2baf726 fix: Fixed cli command. 2026-06-14 21:59:54 -04:00
a56d349da4 docs: Added plan for improving testing. 2026-06-14 21:52:26 -04:00
2229affe69 refactor: Fixed duplicate terminal checks. 2026-06-14 21:36:31 -04:00
6394c42d8b docs: Created table improvement plan. 2026-06-14 21:27:24 -04:00
8e00c78f12 style: Removed unused code. 2026-06-14 21:27:23 -04:00
8d2c5403e8 fix: Removed duplicate insert calls. 2026-06-14 21:27:23 -04:00
7c7d3d5c23 fix: Fixed logic bug in db. 2026-06-14 21:27:23 -04:00
6151a5efaf ci: Updated release-please. 2026-06-14 21:27:23 -04:00
fbb1f86945 docs: updated README.md 2026-06-14 21:27:23 -04:00
0c5aa74256 ci: Updated github action. 2026-06-14 21:27:23 -04:00
eed360895f feat: Removed go code. 2026-06-12 16:35:39 -04:00
75b778453f build: Converted Makefile and flake package. 2026-06-12 16:35:34 -04:00
4ec2b22b52 refactor: removed is_tty. 2026-06-12 15:54:44 -04:00
0276db767e refactor: Switched from age to libsodium. 2026-06-12 15:48:12 -04:00
a0e2c99581 docs: Updated TODOs. 2026-06-12 15:36:10 -04:00
d0dc93ab56 feat(odin): Migrated nushell-completion command to go. 2026-06-12 15:01:50 -04:00
91ada61c06 feat: Added tests. 2026-06-12 14:50:42 -04:00
9b39567720 fix: Fixed the rest of the (tested) leaks. 2026-06-12 14:17:56 -04:00
43dd8aca13 perf: Improved writer performance. 2026-06-12 13:37:09 -04:00
db1b863e7e fix: fixing leaks. 2026-06-12 13:25:50 -04:00
e966050137 fix: Added proper help text to all commands. 2026-06-12 10:45:43 -04:00
7629dd2ce7 fix: Got rid of go fallback code. 2026-06-12 10:28:41 -04:00
7c7ddf46f6 fix: Fixed memory leaks in find_binary. 2026-06-12 10:22:21 -04:00
a1e945a630 feat(odin): Ported init command. 2026-06-12 10:22:21 -04:00
0a332adfdf feat(odin): Ported scan command. 2026-06-12 09:12:55 -04:00
4e1e359076 feat(odin): port check command to odin. 2026-06-12 08:27:14 -04:00
82bec68bd1 fix: Fixing AI oopsies. 2026-06-12 08:02:08 -04:00
2cb6067a3a feat(odin): ported edit-config command to odin. 2026-06-11 21:26:59 -04:00
3668df57d1 feat(odin): ported restore command to odin. 2026-06-11 21:25:11 -04:00
d2127e4780 feat(odin): Ported remove command. 2026-06-11 21:21:59 -04:00
cb7db96781 feat(odin): Added long text and --help flags. 2026-06-11 21:17:52 -04:00
c92155a17b feat(odin): ported backup command. 2026-06-11 21:14:11 -04:00
b1d2416182 feat(odin): ported list command. 2026-06-11 21:05:39 -04:00
40f0b3c36d feat(odin): ported deps command, added utilities (features, tty, table). 2026-06-11 21:05:33 -04:00
d84e43d044 odin: scaffold project with CLI parser, version command, Go fallback 2026-06-11 20:34:53 -04:00
28f96df4c0 feat: Started odin setup. 2026-06-11 20:08:27 -04:00
13 changed files with 216 additions and 241 deletions

View File

@@ -25,4 +25,3 @@ jobs:
# this is a built-in strategy in release-please, see "Action Inputs" # this is a built-in strategy in release-please, see "Action Inputs"
# for more options # for more options
release-type: simple release-type: simple
target-branch: ${{ github.ref_name }}

View File

@@ -1,23 +1,5 @@
# Changelog # Changelog
## [0.3.0](https://github.com/sbrow/envr/compare/v0.2.1...v0.3.0) (2026-06-16)
### ⚠ BREAKING CHANGES
* The encryption format of databases has changed. Age encryption is no longer supported, and no automatic migration path was implemented.
### Features
* All encryption/decryption now happens in-memory. ([fe2b256](https://github.com/sbrow/envr/commit/fe2b256bd61eaf551d53faf3893b473a64a94667))
* Config can be loaded from any path with `--config-file (-c)` flag. ([4a26ee8](https://github.com/sbrow/envr/commit/4a26ee814591e6aab0eb99d2359d51b31011edfe))
* Switched from age to libsodium. ([23b8c2d](https://github.com/sbrow/envr/commit/23b8c2dc671a23cf76cf6746b33806ded9381486))
### Performance Improvements
* Improved writer performance. ([365e914](https://github.com/sbrow/envr/commit/365e9149b1a738ac9119bb5f74dc7e047ecfed5b))
## [0.2.1](https://github.com/sbrow/envr/compare/v0.2.0...v0.2.1) (2026-01-12) ## [0.2.1](https://github.com/sbrow/envr/compare/v0.2.0...v0.2.1) (2026-01-12)

View File

@@ -1,7 +1,12 @@
# TODOs # TODO
Note: These todos can wait until all the subcommands have been ported.
1. Consider giving db its own allocator ## HIGH
1. **db.odin:380-383, 405, 446**`sqlite.bind_text` return values overwritten but never checked. A failed bind means `sqlite.step` operates on unbound params.
## MEDIUM
2. **db.odin:324-327** — Map iteration (`remote_set`) is non-deterministic. Same file can produce different JSON on each backup, causing spurious DB diffs. Sort remotes before storing. 2. **db.odin:324-327** — Map iteration (`remote_set`) is non-deterministic. Same file can produce different JSON on each backup, causing spurious DB diffs. Sort remotes before storing.
@@ -13,14 +18,22 @@
6. **cmd_restore.odin:44**`os.mkdir_all` error silently discarded. Subsequent write failure will be confusing. 6. **cmd_restore.odin:44**`os.mkdir_all` error silently discarded. Subsequent write failure will be confusing.
7. **cmd_edit_config.odin:27**`$EDITOR` used as single binary name. Breaks for multi-word values like `"code -w"`. Needs `strings.fields()`.
8. **config.odin:178**`search_paths` silently ignores `os.user_home_dir` error. If home is empty, `~` isn't expanded. Same class of bug as issue 3. 8. **config.odin:178**`search_paths` silently ignores `os.user_home_dir` error. If home is empty, `~` isn't expanded. Same class of bug as issue 3.
9. **prompt.odin:124**`make([dynamic]bool, len(options))` creates N zero-initialized elements. Works because `false` is the default, but same footgun as original issue 1. Should be `make([dynamic]bool, 0, len(options))`.
## LOW
10. **db.odin:115**`json.unmarshal_string` error not checked. Malformed JSON silently produces empty/partial data. 10. **db.odin:115**`json.unmarshal_string` error not checked. Malformed JSON silently produces empty/partial data.
11. **db.odin:352-353**`hex.encode` error ignored. `string(hex_bytes)` aliases the byte slice. 11. **db.odin:352-353**`hex.encode` error ignored. `string(hex_bytes)` aliases the byte slice.
12. **cmd_sync.odin:80, cmd_list.odin:33, cmd_deps.odin:9**`make([]string, 2)` for table rows never freed. Leaks per row. Defer to memory pass. 12. **cmd_sync.odin:80, cmd_list.odin:33, cmd_deps.odin:9**`make([]string, 2)` for table rows never freed. Leaks per row. Defer to memory pass.
## REFACTOR
13. **cmd_list.odin** — Non-TTY branch builds `ListEntry` structs and marshals JSON separately. Now that `render_json_rows` (issue 1) accepts an `io.Writer` and uses `json.marshal`, unify both branches to use it. Note: will change JSON keys from `"directory"/"path"` to `"Directory"/"Path"`. 13. **cmd_list.odin** — Non-TTY branch builds `ListEntry` structs and marshals JSON separately. Now that `render_json_rows` (issue 1) accepts an `io.Writer` and uses `json.marshal`, unify both branches to use it. Note: will change JSON keys from `"directory"/"path"` to `"Directory"/"Path"`.
14. Check for prealloc opportunities. i.e. `make([dynamic]string)` -> `make([dynamic]string, 5)`. 14. Check for prealloc opportunities. i.e. `make([dynamic]string)` -> `make([dynamic]string, 5)`.
@@ -41,8 +54,6 @@
22. Change struct field names from PascalCase to snake_case. 22. Change struct field names from PascalCase to snake_case.
23. procedures should be ordered by use, main at the top, then in the order they are called from main.
## Double-check AI output ## Double-check AI output
- [ ] cli.odin - [ ] cli.odin

View File

@@ -75,7 +75,7 @@ envr_dir :: proc(config_path: string) -> string {
return filepath.dir(config_path) return filepath.dir(config_path)
} }
data_path :: proc(config_path: string) -> string { data_encrypted_path :: proc(config_path: string) -> string {
path, _ := filepath.join([]string{envr_dir(config_path), "data.envr"}) path, _ := filepath.join([]string{envr_dir(config_path), "data.envr"})
return path return path
} }
@@ -126,7 +126,6 @@ find_ssh_private_keys :: proc() -> (keys: [dynamic]string, ok: bool) {
return return
} }
// Caller is responsible for calling delete_config()
new_config :: proc( new_config :: proc(
private_key_paths: []string, private_key_paths: []string,
cfg_path: string = "~/.envr/config.json", cfg_path: string = "~/.envr/config.json",

View File

@@ -163,8 +163,8 @@ test_envr_dir :: proc(t: ^testing.T) {
} }
@(test) @(test)
test_data_path :: proc(t: ^testing.T) { test_data_encrypted_path :: proc(t: ^testing.T) {
p := data_path("/tmp/envr-fake-home-datapath/config.json") p := data_encrypted_path("/tmp/envr-fake-home-datapath/config.json")
defer delete(p) defer delete(p)
testing.expectf(t, strings.has_suffix(p, "data.envr"), "should end with data.envr, got %s", p) testing.expectf(t, strings.has_suffix(p, "data.envr"), "should end with data.envr, got %s", p)
testing.expectf(t, strings.contains(p, ".envr"), "should contain .envr dir, got %s", p) testing.expectf(t, strings.contains(p, ".envr"), "should contain .envr dir, got %s", p)

123
db.odin
View File

@@ -66,7 +66,7 @@ db_open :: proc(cfg_path: string) -> (Db, bool) {
return Db{}, false return Db{}, false
} }
data_path := data_path(cfg.config_path) data_path := data_encrypted_path(cfg.config_path)
_, stat_err := os.stat(data_path, context.allocator) _, stat_err := os.stat(data_path, context.allocator)
db: ^rawptr db: ^rawptr
@@ -95,31 +95,32 @@ db_open :: proc(cfg_path: string) -> (Db, bool) {
} }
db_close :: proc(d: ^Db) { db_close :: proc(d: ^Db) {
defer sqlite.db_close(d.db)
if d.changed { if d.changed {
rc := sqlite.db_exec(d.db, "VACUUM", nil, nil, nil) tmp_path := make_temp_path()
if rc != sqlite.OK {
fmt.printf("Error vacuuming database: %s\n", sqlite.db_errmsg(d.db)) if !db_vacuum_to_file(d.db, tmp_path) {
os.remove(tmp_path)
sqlite.db_close(d.db)
return return
} }
sz: i64 sqlite_data, read_err := os.read_entire_file_from_path(tmp_path, context.allocator)
data := sqlite.serialize(d.db, "main", &sz, 0) os.remove(tmp_path)
if data == nil { if read_err != nil {
fmt.println("Error: failed to serialize database") fmt.printf("Error reading vacuumed database: %v\n", read_err)
sqlite.db_close(d.db)
return return
} }
defer sqlite.free(data)
sqlite_data := data[:sz]
encrypted, enc_ok := encrypt(sqlite_data, d.cfg.Keys[:]) encrypted, enc_ok := encrypt(sqlite_data, d.cfg.Keys[:])
delete(sqlite_data)
if !enc_ok { if !enc_ok {
fmt.println("Error: encryption failed") fmt.println("Error: encryption failed")
sqlite.db_close(d.db)
return return
} }
data_path := data_path(d.cfg.config_path) data_path := data_encrypted_path(d.cfg.config_path)
envr_d := envr_dir(d.cfg.config_path) envr_d := envr_dir(d.cfg.config_path)
os.mkdir_all(envr_d) os.mkdir_all(envr_d)
@@ -127,11 +128,13 @@ db_close :: proc(d: ^Db) {
delete(encrypted) delete(encrypted)
if write_err != nil { if write_err != nil {
fmt.printf("Error writing encrypted database: %v\n", write_err) fmt.printf("Error writing encrypted database: %v\n", write_err)
sqlite.db_close(d.db)
return return
} }
d.changed = false d.changed = false
} }
sqlite.db_close(d.db)
} }
// Caller is responsible for calling: // Caller is responsible for calling:
@@ -189,12 +192,22 @@ db_list :: proc(d: ^Db, allocator := context.allocator) -> (results: [dynamic]En
return return
} }
db_vacuum_to_file :: proc(db: ^rawptr, path: string) -> bool {
b: strings.Builder
strings.builder_init(&b)
defer strings.builder_destroy(&b)
fmt.sbprintf(&b, "VACUUM INTO '%s'", path)
rc := sqlite.db_exec(db, to_cstring(&b), nil, nil, nil)
if rc != sqlite.OK {
fmt.printf("Error vacuuming database: %s\n", sqlite.db_errmsg(db))
return false
}
return true
}
db_restore_from_encrypted :: proc(db: ^rawptr, cfg: Config) -> bool { db_restore_from_encrypted :: proc(db: ^rawptr, cfg: Config) -> bool {
encrypted_data, read_err := os.read_entire_file_from_path( data_path := data_encrypted_path(cfg.config_path)
data_path(cfg.config_path), encrypted_data, read_err := os.read_entire_file_from_path(data_path, context.temp_allocator)
context.allocator,
)
defer delete(encrypted_data)
if read_err != nil { if read_err != nil {
fmt.printf("Error reading encrypted database: %v\n", read_err) fmt.printf("Error reading encrypted database: %v\n", read_err)
return false return false
@@ -207,31 +220,49 @@ db_restore_from_encrypted :: proc(db: ^rawptr, cfg: Config) -> bool {
} }
defer delete(plaintext) defer delete(plaintext)
n := i64(len(plaintext)) tmp_path := make_temp_path()
buf := sqlite.malloc64(n) write_err := os.write_entire_file(tmp_path, plaintext)
if buf == nil { if write_err != nil {
fmt.println("Error: failed to allocate buffer for deserialization") fmt.printf("Error writing temp database: %v\n", write_err)
return false return false
} }
copy(buf[:len(plaintext)], plaintext) defer os.remove(tmp_path)
rc := sqlite.deserialize( if !db_attach_and_copy(db, tmp_path) {
db,
"main",
buf,
n,
n,
sqlite.DESERIALIZE_FREEONCLOSE | sqlite.DESERIALIZE_RESIZEABLE,
)
if rc != sqlite.OK {
sqlite.free(buf)
fmt.printf("Error deserializing database: %s\n", sqlite.db_errmsg(db))
return false return false
} }
return true return true
} }
db_attach_and_copy :: proc(mem_db: ^rawptr, src_path: string) -> bool {
b: strings.Builder
strings.builder_init(&b)
defer strings.builder_destroy(&b)
fmt.sbprintf(&b, "ATTACH DATABASE '%s' AS source", src_path)
rc := sqlite.db_exec(mem_db, to_cstring(&b), nil, nil, nil)
if rc != sqlite.OK {
fmt.printf("Error attaching database: %s\n", sqlite.db_errmsg(mem_db))
return false
}
rc = sqlite.db_exec(
mem_db,
"INSERT INTO main.envr_env_files SELECT * FROM source.envr_env_files",
nil,
nil,
nil,
)
if rc != sqlite.OK {
fmt.printf("Error copying data: %s\n", sqlite.db_errmsg(mem_db))
sqlite.db_exec(mem_db, "DETACH DATABASE source", nil, nil, nil)
return false
}
sqlite.db_exec(mem_db, "DETACH DATABASE source", nil, nil, nil)
return true
}
get_git_remotes :: proc(dir: string) -> [dynamic]string { get_git_remotes :: proc(dir: string) -> [dynamic]string {
remotes: [dynamic]string remotes: [dynamic]string
@@ -351,34 +382,18 @@ db_insert :: proc(d: ^Db, file: EnvFile) -> bool {
cpath := to_cstring(file.Path) cpath := to_cstring(file.Path)
defer delete(cpath) defer delete(cpath)
rc = sqlite.bind_text(stmt, 1, cpath, -1, nil) rc = sqlite.bind_text(stmt, 1, cpath, -1, nil)
if rc != sqlite.OK {
fmt.printf("Error binding path: %s\n", sqlite.db_errmsg(d.db))
return false
}
cremotes := to_cstring(string(remotes_json)) cremotes := to_cstring(string(remotes_json))
defer delete(cremotes) defer delete(cremotes)
rc = sqlite.bind_text(stmt, 2, cremotes, -1, nil) rc = sqlite.bind_text(stmt, 2, cremotes, -1, nil)
if rc != sqlite.OK {
fmt.printf("Error binding remotes: %s\n", sqlite.db_errmsg(d.db))
return false
}
csha := to_cstring(file.Sha256) csha := to_cstring(file.Sha256)
defer delete(csha) defer delete(csha)
rc = sqlite.bind_text(stmt, 3, csha, -1, nil) rc = sqlite.bind_text(stmt, 3, csha, -1, nil)
if rc != sqlite.OK {
fmt.printf("Error binding sha256: %s\n", sqlite.db_errmsg(d.db))
return false
}
ccontents := to_cstring(file.contents) ccontents := to_cstring(file.contents)
defer delete(ccontents) defer delete(ccontents)
rc = sqlite.bind_text(stmt, 4, ccontents, -1, nil) rc = sqlite.bind_text(stmt, 4, ccontents, -1, nil)
if rc != sqlite.OK {
fmt.printf("Error binding contents: %s\n", sqlite.db_errmsg(d.db))
return false
}
rc = sqlite.step(stmt) rc = sqlite.step(stmt)
if rc != sqlite.DONE { if rc != sqlite.DONE {
@@ -403,10 +418,6 @@ db_fetch :: proc(d: ^Db, path: string, allocator := context.allocator) -> (EnvFi
cpath := to_cstring(path, allocator) cpath := to_cstring(path, allocator)
defer delete(cpath, allocator) defer delete(cpath, allocator)
rc = sqlite.bind_text(stmt, 1, cpath, -1, nil) rc = sqlite.bind_text(stmt, 1, cpath, -1, nil)
if rc != sqlite.OK {
fmt.printf("Error binding path: %s\n", sqlite.db_errmsg(d.db))
return EnvFile{}, false
}
rc = sqlite.step(stmt) rc = sqlite.step(stmt)
if rc == sqlite.DONE { if rc == sqlite.DONE {
fmt.printf("No file found with path: %s\n", path) fmt.printf("No file found with path: %s\n", path)
@@ -448,10 +459,6 @@ db_delete :: proc(d: ^Db, path: string) -> bool {
cpath := to_cstring(path) cpath := to_cstring(path)
defer delete(cpath) defer delete(cpath)
rc = sqlite.bind_text(stmt, 1, cpath, -1, nil) rc = sqlite.bind_text(stmt, 1, cpath, -1, nil)
if rc != sqlite.OK {
fmt.printf("Error binding path: %s\n", sqlite.db_errmsg(d.db))
return false
}
rc = sqlite.step(stmt) rc = sqlite.step(stmt)
if rc != sqlite.DONE { if rc != sqlite.DONE {
fmt.printf("Error deleting: %s\n", sqlite.db_errmsg(d.db)) fmt.printf("Error deleting: %s\n", sqlite.db_errmsg(d.db))

View File

@@ -136,7 +136,7 @@ test_encrypt_write_read_decrypt :: proc(t: ^testing.T) {
} }
@(test) @(test)
test_decrypt_then_deserialize_sqlite :: proc(t: ^testing.T) { test_decrypt_then_attach_sqlite :: proc(t: ^testing.T) {
cfg := fixture_config() cfg := fixture_config()
defer { defer {
delete(cfg.Keys) delete(cfg.Keys)
@@ -164,6 +164,14 @@ test_decrypt_then_deserialize_sqlite :: proc(t: ^testing.T) {
} }
defer delete(plaintext) defer delete(plaintext)
tmp_db_path := fmt.tprintf("/tmp/envr-test-attach-%d.db", os.get_pid())
write_err := os.write_entire_file(tmp_db_path, plaintext)
testing.expectf(t, write_err == nil, "failed to write temp db: %v", write_err)
if write_err != nil {
return
}
defer os.remove(tmp_db_path)
mem_db: ^rawptr mem_db: ^rawptr
rc := sqlite.db_open(":memory:", &mem_db) rc := sqlite.db_open(":memory:", &mem_db)
testing.expectf(t, rc == sqlite.OK, "failed to open in-memory db") testing.expectf(t, rc == sqlite.OK, "failed to open in-memory db")
@@ -172,25 +180,12 @@ test_decrypt_then_deserialize_sqlite :: proc(t: ^testing.T) {
} }
defer sqlite.db_close(mem_db) defer sqlite.db_close(mem_db)
n := i64(len(plaintext)) create_sql: cstring = "CREATE TABLE IF NOT EXISTS envr_env_files (path TEXT PRIMARY KEY NOT NULL, remotes TEXT, sha256 TEXT NOT NULL, contents TEXT NOT NULL)"
buf := sqlite.malloc64(n) rc = sqlite.db_exec(mem_db, create_sql, nil, nil, nil)
testing.expect(t, buf != nil, "malloc64 should succeed") testing.expect(t, rc == sqlite.OK, "failed to create table")
if buf == nil do return
copy(buf[:len(plaintext)], plaintext)
rc = sqlite.deserialize( attach_ok := db_attach_and_copy(mem_db, tmp_db_path)
mem_db, testing.expect(t, attach_ok, "failed to attach and copy")
"main",
buf,
n,
n,
sqlite.DESERIALIZE_FREEONCLOSE | sqlite.DESERIALIZE_RESIZEABLE,
)
testing.expect(t, rc == sqlite.OK, "deserialize should succeed")
if rc != sqlite.OK {
sqlite.free(buf)
return
}
sql: cstring = "SELECT path FROM envr_env_files" sql: cstring = "SELECT path FROM envr_env_files"
stmt: ^rawptr stmt: ^rawptr

View File

@@ -215,7 +215,7 @@ test_db_delete_sets_changed :: proc(t: ^testing.T) {
} }
@(test) @(test)
test_db_serialize :: proc(t: ^testing.T) { test_db_vacuum_to_file :: proc(t: ^testing.T) {
d, ok := make_test_db() d, ok := make_test_db()
testing.expect(t, ok, "failed to create test db") testing.expect(t, ok, "failed to create test db")
if !ok do return if !ok do return
@@ -225,13 +225,20 @@ test_db_serialize :: proc(t: ^testing.T) {
defer delete(f.Remotes) defer delete(f.Remotes)
db_insert(&d, f) db_insert(&d, f)
sz: i64 vacuum_path := fmt.tprintf("/tmp/envr-test-vacuum-%d.db", os.get_pid())
data := sqlite.serialize(d.db, "main", &sz, 0) defer os.remove(vacuum_path)
testing.expect(t, data != nil, "serialize should return non-nil")
if data == nil do return
defer sqlite.free(data)
testing.expect(t, sz > 0, "serialized size should be > 0") testing.expect(t, db_vacuum_to_file(d.db, vacuum_path), "vacuum should succeed")
info, stat_err := os.stat(vacuum_path, context.allocator)
defer os.file_info_delete(info, context.allocator)
testing.expect(t, stat_err == nil, "vacuumed file should exist")
data, read_err := os.read_entire_file_from_path(vacuum_path, context.allocator)
testing.expect(t, read_err == nil, "should read vacuumed file")
defer delete(data)
testing.expect(t, len(data) > 0, "vacuumed file should be non-empty")
} }
@(test) @(test)

View File

@@ -11,12 +11,11 @@
}; };
outputs = outputs =
inputs@{ inputs@{ flake-parts
flake-parts, , nixpkgs
nixpkgs, , nixpkgs-unstable
nixpkgs-unstable, , self
self, , treefmt-nix
treefmt-nix,
}: }:
flake-parts.lib.mkFlake { inherit inputs; } { flake-parts.lib.mkFlake { inherit inputs; } {
imports = [ imports = [
@@ -30,18 +29,7 @@
]; ];
perSystem = perSystem =
{ { pkgs, system, inputs', ... }: {
pkgs,
system,
inputs',
...
}:
let
mysqlite = pkgs.sqlite.overrideAttrs (old: {
configureFlags = (old.configureFlags or [ ]) ++ [ "--enable-deserialize" ];
});
in
{
_module.args.pkgs = import nixpkgs { _module.args.pkgs = import nixpkgs {
inherit system; inherit system;
config.allowUnfree = true; config.allowUnfree = true;
@@ -76,7 +64,7 @@
buildInputs = [ buildInputs = [
pkgs.libsodium pkgs.libsodium
mysqlite pkgs.sqlite
]; ];
buildPhase = '' buildPhase = ''
@@ -99,7 +87,7 @@
nushell nushell
libsodium libsodium
mysqlite sqlite
unstable.odin unstable.odin
unstable.ols unstable.ols

View File

@@ -5,8 +5,6 @@ import "core:fmt"
import "core:os" import "core:os"
main :: proc() { main :: proc() {
defer free_all(context.temp_allocator)
cmd, ok := parse_args(os.args, os.to_writer(os.stdout), os.to_writer(os.stderr)) cmd, ok := parse_args(os.args, os.to_writer(os.stdout), os.to_writer(os.stderr))
defer bufio.writer_flush(cmd.out_buf) defer bufio.writer_flush(cmd.out_buf)
if !ok { if !ok {

View File

@@ -3,9 +3,36 @@ package main
import "core:fmt" import "core:fmt"
import "core:sys/posix" import "core:sys/posix"
MultiSelect_Result :: enum { Raw_State :: struct {
Confirm, original: posix.termios,
Cancel, fd: posix.FD,
}
enable_raw_mode :: proc(fd: posix.FD) -> (Raw_State, bool) {
state: Raw_State
state.fd = fd
if posix.tcgetattr(fd, &state.original) != .OK {
return state, false
}
attr: posix.termios = state.original
attr.c_lflag -= {.ICANON, .ECHO, .ISIG, .IEXTEN}
attr.c_iflag -= {.IXON, .ICRNL, .BRKINT, .INPCK, .ISTRIP}
attr.c_oflag -= {.OPOST}
attr.c_cflag += {.CS8}
attr.c_cc[.VMIN] = 1
attr.c_cc[.VTIME] = 0
if posix.tcsetattr(fd, .TCSAFLUSH, &attr) != .OK {
return state, false
}
return state, true
}
disable_raw_mode :: proc(state: ^Raw_State) {
posix.tcsetattr(state.fd, .TCSAFLUSH, &state.original)
} }
Key :: enum { Key :: enum {
@@ -17,9 +44,71 @@ Key :: enum {
Unknown, Unknown,
} }
Raw_State :: struct { read_key :: proc() -> Key {
original: posix.termios, buf: [3]u8
fd: posix.FD,
n := posix.read(posix.STDIN_FILENO, &buf[0], 1)
if n <= 0 {
return .Unknown
}
switch buf[0] {
case ' ':
return .Space
case '\n', '\r':
return .Enter
case 0x03:
return .Escape
case 0x1b:
tv: posix.timeval
tv.tv_sec = 0
tv.tv_usec = posix.suseconds_t(100000)
set: posix.fd_set
posix.FD_ZERO(&set)
posix.FD_SET(posix.STDIN_FILENO, &set)
ready := posix.select(1, &set, nil, nil, &tv)
if ready <= 0 {
return .Escape
}
n2 := posix.read(posix.STDIN_FILENO, &buf[1], 1)
if n2 <= 0 || buf[1] != '[' {
return .Escape
}
posix.FD_ZERO(&set)
posix.FD_SET(posix.STDIN_FILENO, &set)
tv.tv_sec = 0
tv.tv_usec = posix.suseconds_t(100000)
ready = posix.select(1, &set, nil, nil, &tv)
if ready <= 0 {
return .Escape
}
n3 := posix.read(posix.STDIN_FILENO, &buf[2], 1)
if n3 <= 0 {
return .Escape
}
switch buf[2] {
case 'A':
return .Up
case 'B':
return .Down
case:
return .Escape
}
case:
return .Unknown
}
}
MultiSelect_Result :: enum {
Confirm,
Cancel,
} }
MAX_VISIBLE :: 7 MAX_VISIBLE :: 7
@@ -36,7 +125,7 @@ multi_select :: proc(
return return
} }
selected = make([dynamic]bool, 0, len(options)) selected = make([dynamic]bool, len(options))
cursor: int = 0 cursor: int = 0
scroll_offset: int = 0 scroll_offset: int = 0
@@ -110,92 +199,3 @@ render_options :: proc(
return end - scroll_offset return end - scroll_offset
} }
enable_raw_mode :: proc(fd: posix.FD) -> (Raw_State, bool) {
state: Raw_State
state.fd = fd
if posix.tcgetattr(fd, &state.original) != .OK {
return state, false
}
attr: posix.termios = state.original
attr.c_lflag -= {.ICANON, .ECHO, .ISIG, .IEXTEN}
attr.c_iflag -= {.IXON, .ICRNL, .BRKINT, .INPCK, .ISTRIP}
attr.c_oflag -= {.OPOST}
attr.c_cflag += {.CS8}
attr.c_cc[.VMIN] = 1
attr.c_cc[.VTIME] = 0
if posix.tcsetattr(fd, .TCSAFLUSH, &attr) != .OK {
return state, false
}
return state, true
}
disable_raw_mode :: proc(state: ^Raw_State) {
posix.tcsetattr(state.fd, .TCSAFLUSH, &state.original)
}
read_key :: proc() -> Key {
buf: [3]u8
n := posix.read(posix.STDIN_FILENO, &buf[0], 1)
if n <= 0 {
return .Unknown
}
switch buf[0] {
case ' ':
return .Space
case '\n', '\r':
return .Enter
case 0x03:
return .Escape
case 0x1b:
tv: posix.timeval
tv.tv_sec = 0
tv.tv_usec = posix.suseconds_t(100000)
set: posix.fd_set
posix.FD_ZERO(&set)
posix.FD_SET(posix.STDIN_FILENO, &set)
ready := posix.select(1, &set, nil, nil, &tv)
if ready <= 0 {
return .Escape
}
n2 := posix.read(posix.STDIN_FILENO, &buf[1], 1)
if n2 <= 0 || buf[1] != '[' {
return .Escape
}
posix.FD_ZERO(&set)
posix.FD_SET(posix.STDIN_FILENO, &set)
tv.tv_sec = 0
tv.tv_usec = posix.suseconds_t(100000)
ready = posix.select(1, &set, nil, nil, &tv)
if ready <= 0 {
return .Escape
}
n3 := posix.read(posix.STDIN_FILENO, &buf[2], 1)
if n3 <= 0 {
return .Escape
}
switch buf[2] {
case 'A':
return .Up
case 'B':
return .Down
case:
return .Escape
}
case:
return .Unknown
}
}

View File

@@ -8,9 +8,6 @@ OK :: 0
ROW :: 100 ROW :: 100
DONE :: 101 DONE :: 101
DESERIALIZE_FREEONCLOSE :: 1
DESERIALIZE_RESIZEABLE :: 2
foreign lib { foreign lib {
@(link_name="sqlite3_open") @(link_name="sqlite3_open")
db_open :: proc(filename: cstring, ppDb: ^^rawptr) -> c.int --- db_open :: proc(filename: cstring, ppDb: ^^rawptr) -> c.int ---
@@ -34,12 +31,4 @@ foreign lib {
bind_text :: proc(stmt: ^rawptr, idx: c.int, val: cstring, n: c.int, destructor: rawptr) -> c.int --- bind_text :: proc(stmt: ^rawptr, idx: c.int, val: cstring, n: c.int, destructor: rawptr) -> c.int ---
@(link_name="sqlite3_changes") @(link_name="sqlite3_changes")
changes :: proc(db: ^rawptr) -> c.int --- changes :: proc(db: ^rawptr) -> c.int ---
@(link_name="sqlite3_serialize")
serialize :: proc(db: ^rawptr, zSchema: cstring, piSize: ^i64, mFlags: u32) -> [^]u8 ---
@(link_name="sqlite3_deserialize")
deserialize :: proc(db: ^rawptr, zSchema: cstring, pData: [^]u8, szDb: i64, szBuf: i64, mFlags: u32) -> c.int ---
@(link_name="sqlite3_malloc64")
malloc64 :: proc(n: i64) -> [^]u8 ---
@(link_name="sqlite3_free")
free :: proc(p: rawptr) ---
} }

View File

@@ -1 +1 @@
0.3.0 0.2.0