summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lua/clever_f/acquisition_service.lua23
-rw-r--r--tests/run.lua24
2 files changed, 46 insertions, 1 deletions
diff --git a/lua/clever_f/acquisition_service.lua b/lua/clever_f/acquisition_service.lua
index 99edf83..707f568 100644
--- a/lua/clever_f/acquisition_service.lua
+++ b/lua/clever_f/acquisition_service.lua
@@ -301,6 +301,27 @@ function AcquisitionService:started_scope_count()
return service_records[self].started_scope_count
end
+function M.is_terminal_artifact(packet)
+ packet = domain.InputPacket.from_table(packet)
+ if packet.kind ~= domain.InputPacketKind.RAW_BYTES then
+ return false
+ end
+ local bytes = packet:bytes()
+ return #bytes == 3
+ and bytes[1] == 0x80
+ and bytes[2] == 0xfd
+ and bytes[3] == 0x60
+end
+
+local function read_input_packet(host)
+ while true do
+ local packet = domain.InputPacket.from_table(host:read_input())
+ if not M.is_terminal_artifact(packet) then
+ return packet
+ end
+ end
+end
+
local function direct_preview_settings(policy_service)
if type(policy_service.sample_direct_preview) == "function" then
return policy_service:sample_direct_preview()
@@ -356,7 +377,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()))
+ scope:set_input_packet(read_input_packet(record.host))
return request
end
diff --git a/tests/run.lua b/tests/run.lua
index faad4ba..3f4c957 100644
--- a/tests/run.lua
+++ b/tests/run.lua
@@ -5129,6 +5129,30 @@ test("Acquisition reads one raw packet after sequence start", function()
same(1, reads)
end)
+test("Acquisition discards the terminal artifact packet", function()
+ fresh_sequence_state()
+ local artifact = domain.InputPacket.raw_bytes({ 0x80, 0xfd, 0x60 })
+ local target_packet = domain.InputPacket.text("x")
+ local host = MemoryHost.new({
+ configuration = { mark_cursor = false },
+ input_packets = { artifact, target_packet },
+ })
+ local service = acquisition_service.new(host)
+
+ service:acquire("f", "n", domain.Position.new(1, 1), nil, nil)
+ truthy(acquisition_service.is_terminal_artifact(artifact))
+ falsy(acquisition_service.is_terminal_artifact(target_packet))
+ same(target_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(2, reads)
+end)
+
for _, item in ipairs(tests) do
local ok, failure = xpcall(item.body, debug.traceback)
if not ok then