@@ -103,24 +103,24 @@ pub const BlocksView = struct {
103103 var row : u16 = 0 ;
104104
105105 // Header
106- try writeString (surface , 2 , row , "Blocks" , styles .styles .title );
106+ try writeString (surface , ctx , 2 , row , "Blocks" , styles .styles .title );
107107 row += 1 ;
108- try writeString (surface , 2 , row , "Block Explorer" , styles .styles .muted );
108+ try writeString (surface , ctx , 2 , row , "Block Explorer" , styles .styles .muted );
109109 row += 2 ;
110110
111111 // Column headers
112- try writeString (surface , 2 , row , "Block" , styles .styles .muted );
113- try writeString (surface , 12 , row , "Hash" , styles .styles .muted );
114- try writeString (surface , 36 , row , "Txs" , styles .styles .muted );
115- try writeString (surface , 44 , row , "Gas Used" , styles .styles .muted );
116- try writeString (surface , 60 , row , "Timestamp" , styles .styles .muted );
112+ try writeString (surface , ctx , 2 , row , "Block" , styles .styles .muted );
113+ try writeString (surface , ctx , 12 , row , "Hash" , styles .styles .muted );
114+ try writeString (surface , ctx , 36 , row , "Txs" , styles .styles .muted );
115+ try writeString (surface , ctx , 44 , row , "Gas Used" , styles .styles .muted );
116+ try writeString (surface , ctx , 60 , row , "Timestamp" , styles .styles .muted );
117117 row += 1 ;
118118 try drawLine (surface , row , max_size .width , styles .styles .muted );
119119 row += 1 ;
120120
121121 // Block list
122122 if (self .blocks .len == 0 ) {
123- try writeString (surface , 2 , row , "No blocks yet" , styles .styles .muted );
123+ try writeString (surface , ctx , 2 , row , "No blocks yet" , styles .styles .muted );
124124 } else {
125125 for (self .blocks , 0.. ) | block , i | {
126126 if (row >= max_size .height - 3 ) break ;
@@ -130,28 +130,28 @@ pub const BlocksView = struct {
130130
131131 // Selection indicator
132132 if (is_selected ) {
133- try writeString (surface , 0 , row , ">" , styles .styles .value );
133+ try writeString (surface , ctx , 0 , row , ">" , styles .styles .value );
134134 }
135135
136136 // Block number
137137 const num_str = try std .fmt .allocPrint (ctx .arena , "#{d}" , .{block .number });
138- try writeString (surface , 2 , row , num_str , row_style );
138+ try writeString (surface , ctx , 2 , row , num_str , row_style );
139139
140140 // Hash (shortened)
141141 const short_hash = if (block .hash .len > 18 ) block .hash [0.. 18] else block .hash ;
142- try writeString (surface , 12 , row , short_hash , row_style );
142+ try writeString (surface , ctx , 12 , row , short_hash , row_style );
143143
144144 // Transaction count
145145 const tx_count = try std .fmt .allocPrint (ctx .arena , "{d}" , .{block .transactions .len });
146- try writeString (surface , 36 , row , tx_count , row_style );
146+ try writeString (surface , ctx , 36 , row , tx_count , row_style );
147147
148148 // Gas used
149149 const gas_str = try std .fmt .allocPrint (ctx .arena , "{d}" , .{block .gas_used });
150- try writeString (surface , 44 , row , gas_str , row_style );
150+ try writeString (surface , ctx , 44 , row , gas_str , row_style );
151151
152152 // Timestamp
153153 const ts_str = try formatTimestamp (ctx .arena , block .timestamp );
154- try writeString (surface , 60 , row , ts_str , styles .styles .muted );
154+ try writeString (surface , ctx , 60 , row , ts_str , styles .styles .muted );
155155
156156 row += 1 ;
157157 }
@@ -162,61 +162,61 @@ pub const BlocksView = struct {
162162
163163 fn drawDetail (self : * BlocksView , ctx : vxfw.DrawContext , surface : * vxfw.Surface , max_size : vxfw.Size ) ! vxfw.Surface {
164164 const block = self .selected_block orelse {
165- try writeString (surface , 2 , 0 , "Block not found" , styles .styles .err );
165+ try writeString (surface , ctx , 2 , 0 , "Block not found" , styles .styles .err );
166166 return surface .* ;
167167 };
168168
169169 var row : u16 = 0 ;
170170
171171 // Header
172172 const title = try std .fmt .allocPrint (ctx .arena , "Block #{d}" , .{block .number });
173- try writeString (surface , 2 , row , title , styles .styles .title );
173+ try writeString (surface , ctx , 2 , row , title , styles .styles .title );
174174 row += 2 ;
175175
176176 // Block details
177- try writeString (surface , 2 , row , "Hash:" , styles .styles .muted );
177+ try writeString (surface , ctx , 2 , row , "Hash:" , styles .styles .muted );
178178 row += 1 ;
179- try writeString (surface , 4 , row , block .hash , styles .styles .value );
179+ try writeString (surface , ctx , 4 , row , block .hash , styles .styles .value );
180180 row += 2 ;
181181
182- try writeString (surface , 2 , row , "Parent Hash:" , styles .styles .muted );
182+ try writeString (surface , ctx , 2 , row , "Parent Hash:" , styles .styles .muted );
183183 row += 1 ;
184- try writeString (surface , 4 , row , block .parent_hash , styles .styles .normal );
184+ try writeString (surface , ctx , 4 , row , block .parent_hash , styles .styles .normal );
185185 row += 2 ;
186186
187- try writeString (surface , 2 , row , "Miner:" , styles .styles .muted );
187+ try writeString (surface , ctx , 2 , row , "Miner:" , styles .styles .muted );
188188 row += 1 ;
189- try writeString (surface , 4 , row , block .miner , styles .styles .normal );
189+ try writeString (surface , ctx , 4 , row , block .miner , styles .styles .normal );
190190 row += 2 ;
191191
192192 // Stats row
193193 const gas_str = try std .fmt .allocPrint (ctx .arena , "Gas Used: {d} / {d}" , .{ block .gas_used , block .gas_limit });
194- try writeString (surface , 2 , row , gas_str , styles .styles .normal );
194+ try writeString (surface , ctx , 2 , row , gas_str , styles .styles .normal );
195195 row += 1 ;
196196
197197 const size_str = try std .fmt .allocPrint (ctx .arena , "Size: {d} bytes" , .{block .size });
198- try writeString (surface , 2 , row , size_str , styles .styles .normal );
198+ try writeString (surface , ctx , 2 , row , size_str , styles .styles .normal );
199199 row += 2 ;
200200
201- try writeString (surface , 2 , row , "Timestamp:" , styles .styles .muted );
201+ try writeString (surface , ctx , 2 , row , "Timestamp:" , styles .styles .muted );
202202 row += 1 ;
203203 const ts_str = try formatTimestamp (ctx .arena , block .timestamp );
204- try writeString (surface , 4 , row , ts_str , styles .styles .normal );
204+ try writeString (surface , ctx , 4 , row , ts_str , styles .styles .normal );
205205 row += 2 ;
206206
207207 // Transactions section
208208 const tx_title = try std .fmt .allocPrint (ctx .arena , "TRANSACTIONS ({d})" , .{block .transactions .len });
209- try writeString (surface , 2 , row , tx_title , styles .styles .title );
209+ try writeString (surface , ctx , 2 , row , tx_title , styles .styles .title );
210210 row += 1 ;
211211 try drawLine (surface , row , max_size .width , styles .styles .muted );
212212 row += 1 ;
213213
214214 if (block .transactions .len == 0 ) {
215- try writeString (surface , 2 , row , "No transactions in this block" , styles .styles .muted );
215+ try writeString (surface , ctx , 2 , row , "No transactions in this block" , styles .styles .muted );
216216 } else {
217217 for (block .transactions ) | tx_hash | {
218218 if (row >= max_size .height - 2 ) break ;
219- try writeString (surface , 2 , row , tx_hash , styles .styles .normal );
219+ try writeString (surface , ctx , 2 , row , tx_hash , styles .styles .normal );
220220 row += 1 ;
221221 }
222222 }
@@ -227,22 +227,25 @@ pub const BlocksView = struct {
227227
228228// Helper functions
229229
230- fn writeString (surface : * vxfw.Surface , col : u16 , row : u16 , text : []const u8 , style : vaxis.Style ) ! void {
230+ fn writeString (surface : * vxfw.Surface , ctx : vxfw.DrawContext , col : u16 , row : u16 , text : []const u8 , style : vaxis.Style ) ! void {
231231 var c = col ;
232- for (text ) | char | {
232+ var iter = ctx .graphemeIterator (text );
233+ while (iter .next ()) | grapheme_result | {
233234 if (c >= surface .size .width ) break ;
235+ const grapheme = grapheme_result .bytes (text );
236+ const width : u8 = @intCast (ctx .stringWidth (grapheme ));
234237 surface .writeCell (c , row , .{
235- .char = .{ .grapheme = &[ _ ] u8 { char } , .width = 1 },
238+ .char = .{ .grapheme = grapheme , .width = width },
236239 .style = style ,
237240 });
238- c += 1 ;
241+ c += width ;
239242 }
240243}
241244
242245fn drawLine (surface : * vxfw.Surface , row : u16 , width : u16 , style : vaxis.Style ) ! void {
243246 for (0.. width ) | x | {
244247 surface .writeCell (@intCast (x ), row , .{
245- .char = .{ .grapheme = "β " , .width = 1 },
248+ .char = .{ .grapheme = "- " , .width = 1 },
246249 .style = style ,
247250 });
248251 }
0 commit comments