@@ -5,22 +5,13 @@ Output.__index = Output
55
66--- @class Output
77--- @field lines table<number , string>
8- --- @field metadata table<number , OutputMetadata>
98--- @field extmarks table<number , OutputExtmark>
109--- @field actions OutputAction[]
1110--- @field add_line fun ( self : Output , line : string , fit ?: boolean ): number
1211--- @field get_line fun ( self : Output , idx : number ): string ?
13- --- @field get_metadata fun ( self : Output , idx : number ): OutputMetadata ?
14- --- @field get_nearest_metadata fun ( self : Output , idx : number , predicate ?: function , direction ?: string ): OutputMetadata | nil
15- --- @field get_all_metadata fun ( self : Output ): OutputMetadata[]
16- --- @field get_previous_snapshot fun ( self : Output , line : number ): string ?
17- --- @field get_next_snapshot fun ( self : Output , line : number ): string ?
18- --- @field get_first_snapshot fun ( self : Output ): string ?
19- --- @field get_last_snapshot fun ( self : Output ): string ?
2012--- @field merge_line fun ( self : Output , idx : number , text : string )
2113--- @field add_lines fun ( self : Output , lines : string[] , prefix ?: string )
2214--- @field add_empty_line fun ( self : Output ): number ?
23- --- @field add_metadata fun ( self : Output , metadata : OutputMetadata ): number ?
2415--- @field clear fun ( self : Output )
2516--- @field get_line_count fun ( self : Output ): number
2617--- @field get_lines fun ( self : Output ): string[]
@@ -33,7 +24,6 @@ Output.__index = Output
3324function Output .new ()
3425 local self = setmetatable ({}, Output )
3526 self .lines = {}
36- self .metadata = {}
3727 self .extmarks = {}
3828 self .actions = {}
3929 return self
@@ -59,75 +49,6 @@ function Output:get_line(idx)
5949 return self .lines [idx ]
6050end
6151
62- --- Get metadata for line
63- --- @param idx number
64- --- @return OutputMetadata | nil
65- function Output :get_metadata (idx )
66- if not self .metadata [idx ] then
67- return nil
68- end
69- return vim .deepcopy (self .metadata [idx ])
70- end
71-
72- --- @param idx number
73- --- @param predicate ? fun ( metadata : OutputMetadata ): boolean Optional predicate to filter metadata
74- --- @param direction ? ' next' | ' previous' Optional direction to search for metadata
75- --- @return OutputMetadata | nil
76- function Output :get_nearest_metadata (idx , predicate , direction )
77- local step = direction == ' next' and 1 or - 1
78- local limit = step == 1 and # self .lines or 1
79- for i = idx , limit , step do
80- local metadata = self .metadata [i ]
81- if predicate and metadata then
82- if predicate (metadata ) then
83- return vim .deepcopy (metadata )
84- end
85- elseif not predicate and metadata then
86- return vim .deepcopy (metadata )
87- end
88- end
89- end
90-
91- --- Get metadata for all lines
92- --- @return OutputMetadata[]
93- function Output :get_all_metadata ()
94- return vim .deepcopy (self .metadata or {})
95- end
96-
97- --- @param line number Buffer line number
98- --- @return string | nil Snapshot commit hash if available
99- function Output :get_previous_snapshot (line )
100- local metadata = self :get_nearest_metadata (line , function (metadata )
101- return metadata .snapshot ~= nil
102- end , ' previous' )
103- return metadata and metadata .snapshot or nil
104- end
105-
106- --- @param line number Buffer line number
107- --- @return string | nil Snapshot commit hash if available
108- function Output :get_next_snapshot (line )
109- local metadata = self :get_nearest_metadata (line , function (metadata )
110- return metadata .snapshot ~= nil
111- end , ' next' )
112- return metadata and metadata .snapshot or nil
113- end
114-
115- --- @return string | nil Snapshot commit hash if available
116- function Output :get_first_snapshot ()
117- local metadata = self :get_nearest_metadata (1 , function (metadata )
118- return metadata .snapshot ~= nil
119- end , ' next' )
120- return metadata and metadata .snapshot or nil
121- end
122-
123- --- @return string | nil Snapshot commit hash if available
124- function Output :get_last_snapshot ()
125- local metadata = self :get_nearest_metadata (# self .lines , function (metadata )
126- return metadata .snapshot ~= nil
127- end , ' previous' )
128- return metadata and metadata .snapshot or nil
129- end
130-
13152--- Merge text into an existing line
13253--- @param idx number
13354--- @param text string
@@ -162,22 +83,9 @@ function Output:add_empty_line()
16283 return nil
16384end
16485
165- --- Add metadata to the last line
166- --- @param metadata OutputMetadata
167- --- @return number ? index The index of the last line , or nil if no lines exist
168- function Output :add_metadata (metadata )
169- if # self .lines == 0 then
170- return nil
171- end
172- local last_index = # self .lines
173- self .metadata [last_index ] = metadata
174- return last_index
175- end
176-
177- --- Clear all lines and metadata
86+ --- Clear all lines, extmarks, and actions
17887function Output :clear ()
17988 self .lines = {}
180- self .metadata = {}
18189 self .extmarks = {}
18290 self .actions = {}
18391end
0 commit comments