summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJackson Moore <jacksonmoore@tuta.io>2026-09-04 12:01:22 +0200
committerJackson Moore <jacksonmoore@tuta.io>2026-09-04 12:01:22 +0200
commitbd73a648242afb055d03406a87b67c156e087da2 (patch)
treed0eca58bb1918b8aa38a4fb9f3ad9802c54a4a01
parent14bda1fd9623de16b8b9d1cd0dba2433d09ad529 (diff)
Read raw acquisition packets
-rw-r--r--lua/clever_f/acquisition_service.lua17
-rw-r--r--tests/run.lua44
2 files changed, 60 insertions, 1 deletions
diff --git a/lua/clever_f/acquisition_service.lua b/lua/clever_f/acquisition_service.lua
index da9ae0f..99edf83 100644
--- a/lua/clever_f/acquisition_service.lua
+++ b/lua/clever_f/acquisition_service.lua
@@ -116,6 +116,8 @@ function TemporaryResourceScope.new(request, feedback)
active = true,
cursor_marker = nil,
direct_marker = nil,
+ cursor_presentation_lease = nil,
+ input_packet = nil,
}
return scope
end
@@ -141,6 +143,14 @@ function TemporaryResourceScope:set_direct_marker(marker)
return set_scope_resource(self, "direct_marker", marker)
end
+function TemporaryResourceScope:set_cursor_presentation_lease(lease)
+ return set_scope_resource(self, "cursor_presentation_lease", lease)
+end
+
+function TemporaryResourceScope:set_input_packet(packet)
+ return set_scope_resource(self, "input_packet", packet)
+end
+
function TemporaryResourceScope:release()
local record = scope_records[self]
if record == nil then
@@ -309,6 +319,12 @@ function AcquisitionService:acquire(descriptor, context, position, count, macro_
local scope = self:start_temporary_scope(request)
local record = service_records[self]
local acquisition = record.policy:sample_acquisition()
+ local interactive = not request.macro_state.executing
+ scope:set_cursor_presentation_lease(
+ record.feedback:create_cursor_presentation_lease(
+ interactive and acquisition.hide_cursor_on_cmdline
+ )
+ )
if acquisition.mark_cursor then
scope:set_cursor_marker(record.feedback:create_cursor_marker(
request.position,
@@ -340,6 +356,7 @@ function AcquisitionService:acquire(descriptor, context, position, count, macro_
record.host:show_prompt(M.PROMPT)
end
record.transitions:BeginAcquisition(request.context, request.descriptor)
+ scope:set_input_packet(domain.InputPacket.from_table(record.host:read_input()))
return request
end
diff --git a/tests/run.lua b/tests/run.lua
index cab79c5..faad4ba 100644
--- a/tests/run.lua
+++ b/tests/run.lua
@@ -4898,7 +4898,9 @@ end)
test("Acquisition starts one temporary resource scope", function()
fresh_sequence_state()
- local service = acquisition_service.new(MemoryHost.new())
+ local service = acquisition_service.new(MemoryHost.new({
+ input_packets = { { kind = "text", text = "a" } },
+ }))
local request = service:acquire(
"f",
"n",
@@ -4920,6 +4922,7 @@ test("Acquisition creates cursor markers only when enabled", function()
local host = MemoryHost.new({
cursor = { line = 1, byte_column = 4 },
configuration = { mark_cursor = true },
+ input_packets = { { kind = "text", text = "a" } },
})
local service = acquisition_service.new({
host = host,
@@ -4936,6 +4939,7 @@ test("Acquisition creates cursor markers only when enabled", function()
fresh_sequence_state()
local disabled = acquisition_service.new(MemoryHost.new({
configuration = { mark_cursor = false },
+ input_packets = { { kind = "text", text = "a" } },
}))
disabled:acquire("f", "n", domain.Position.new(1, 1), nil, nil)
same(nil, disabled:last_temporary_scope().cursor_marker)
@@ -4945,6 +4949,7 @@ test("Interactive acquisition redraws after cursor marker creation", function()
fresh_sequence_state()
local host = MemoryHost.new({
configuration = { mark_cursor = true },
+ input_packets = { { kind = "text", text = "a" } },
})
local service = acquisition_service.new(host)
service:acquire("f", "n", domain.Position.new(1, 1), nil, nil)
@@ -4965,6 +4970,7 @@ test("Interactive acquisition redraws after cursor marker creation", function()
fresh_sequence_state()
local macro_host = MemoryHost.new({
configuration = { mark_cursor = true },
+ input_packets = { { kind = "text", text = "a" } },
})
acquisition_service.new(macro_host):acquire(
"f",
@@ -4988,6 +4994,7 @@ test("Interactive acquisition creates enabled direct previews", function()
ignore_case = false,
smart_case = false,
},
+ input_packets = { { kind = "text", text = "a" } },
})
local service = acquisition_service.new({
host = host,
@@ -5017,6 +5024,7 @@ test("Interactive acquisition creates enabled direct previews", function()
local macro_host = MemoryHost.new({
buffer_lines = { "xaxa" },
configuration = { mark_cursor = false, mark_direct = true },
+ input_packets = { { kind = "text", text = "a" } },
})
local macro_service = acquisition_service.new(macro_host)
macro_service:acquire(
@@ -5037,6 +5045,7 @@ test("Acquisition emits the exact enabled prompt", function()
mark_direct = false,
show_prompt = true,
},
+ input_packets = { { kind = "text", text = "a" } },
})
acquisition_service.new(host):acquire(
"f",
@@ -5054,6 +5063,7 @@ test("Acquisition emits the exact enabled prompt", function()
mark_cursor = false,
show_prompt = true,
},
+ input_packets = { { kind = "text", text = "a" } },
})
acquisition_service.new(macro_host):acquire(
"f",
@@ -5069,6 +5079,7 @@ test("Acquisition begins sequence state before input", function()
local state, transitions = fresh_sequence_state()
local host = MemoryHost.new({
configuration = { mark_cursor = false },
+ input_packets = { { kind = "text", text = "a" } },
})
acquisition_service.new({
host = host,
@@ -5087,6 +5098,37 @@ test("Acquisition begins sequence state before input", function()
same(nil, record.previous_target)
end)
+test("Acquisition reads one raw packet after sequence start", function()
+ local state, transitions = fresh_sequence_state()
+ local packet = domain.InputPacket.raw_bytes({ 0x41 })
+ local host = MemoryHost.new({
+ configuration = { mark_cursor = false },
+ input_packets = { packet },
+ })
+ local original_read_input = host.read_input
+ local state_at_read
+ function host:read_input()
+ state_at_read = state:get_context("n")
+ return original_read_input(self)
+ end
+ local service = acquisition_service.new({
+ host = host,
+ transitions = transitions,
+ })
+
+ service:acquire("f", "n", domain.Position.new(1, 1), nil, nil)
+ same(domain.Descriptor.FIND_FORWARD, state_at_read.previous_descriptor)
+ truthy(state_at_read.first_move)
+ same(packet, service:last_temporary_scope().input_packet)
+ local reads = 0
+ for _, operation in ipairs(host:operations()) do
+ if operation.operation == "read_input" then
+ reads = reads + 1
+ end
+ end
+ same(1, reads)
+end)
+
for _, item in ipairs(tests) do
local ok, failure = xpcall(item.body, debug.traceback)
if not ok then