summaryrefslogtreecommitdiff
path: root/src/hist_view.c
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-15 13:04:32 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-15 13:04:32 +0300
commitbdaedce69b17b654bd0060579dd9b9ff120009b5 (patch)
tree0e9cd8597652263a96c48ba678fb0b66e1fc131b /src/hist_view.c
parentba75c8b0a1bba03ad92c53375432f122ddb4cb98 (diff)
parentdcebf9c7f954a55350b68d0ead1935612c4e2e05 (diff)
Merge branch 'wt/rename' into api-hardening
# Conflicts: # README.md
Diffstat (limited to 'src/hist_view.c')
-rw-r--r--src/hist_view.c86
1 files changed, 43 insertions, 43 deletions
diff --git a/src/hist_view.c b/src/hist_view.c
index 362e995..1cbbb07 100644
--- a/src/hist_view.c
+++ b/src/hist_view.c
@@ -3,7 +3,7 @@
#include <stdlib.h>
#include <string.h>
-void term_hist_view_free(struct hist_view *v)
+void wsap_vtcore_hist_view_free(struct hist_view *v)
{
if (!v)
return;
@@ -37,10 +37,10 @@ static bool current(const struct hist_view *v, const struct hist *h, int cols)
return v->index_cols == cols && v->epoch == h->index_epoch &&
v->first_id == hist_first_id(h) && v->end_id == hist_end_id(h) &&
v->head == h->head && v->tail == h->tail &&
- v->last_cells == (h->lines ? term_hist_line_cells(h, hist_end_id(h) - 1) : 0);
+ v->last_cells == (h->lines ? wsap_vtcore_hist_line_cells(h, hist_end_id(h) - 1) : 0);
}
-bool term_hist_view_sync(struct hist_view *v, const struct hist *h, int cols)
+bool wsap_vtcore_hist_view_sync(struct hist_view *v, const struct hist *h, int cols)
{
if (current(v, h, cols))
return true;
@@ -54,7 +54,7 @@ bool term_hist_view_sync(struct hist_view *v, const struct hist *h, int cols)
if (h->lines > v->cap || !v->cap) {
if (h->lines > (UINT32_C(1) << 31))
return false;
- uint32_t cap = term_next_pow2_32(h->lines < 16 ? 16 : h->lines);
+ uint32_t cap = wsap_vtcore_next_pow2_32(h->lines < 16 ? 16 : h->lines);
if (cap == UINT32_MAX)
return false;
uint64_t *tree = calloc((size_t)cap + 1, sizeof(*tree));
@@ -75,7 +75,7 @@ bool term_hist_view_sync(struct hist_view *v, const struct hist *h, int cols)
memset(v->counts, 0, (size_t)v->cap * sizeof(*v->counts));
memset(v->fenwick, 0, ((size_t)v->cap + 1) * sizeof(*v->fenwick));
for (uint64_t id = first; id < end; id++)
- v->counts[(uint32_t)id & (v->cap - 1)] = (uint32_t)term_hist_line_estimate(h, id, cols);
+ v->counts[(uint32_t)id & (v->cap - 1)] = (uint32_t)wsap_vtcore_hist_line_estimate(h, id, cols);
/* Build all tree nodes in one pass. */
for (uint32_t i = 1; i <= v->cap; i++) {
v->fenwick[i] += v->counts[i - 1];
@@ -88,10 +88,10 @@ bool term_hist_view_sync(struct hist_view *v, const struct hist *h, int cols)
for (uint64_t id = v->first_id; id < first; id++)
set_count(v, id, 0);
/* Only the old final line can grow or close. */
- if (v->end_id > first && term_hist_line_cells(h, v->end_id - 1) != v->last_cells)
- set_count(v, v->end_id - 1, (uint32_t)term_hist_line_estimate(h, v->end_id - 1, cols));
+ if (v->end_id > first && wsap_vtcore_hist_line_cells(h, v->end_id - 1) != v->last_cells)
+ set_count(v, v->end_id - 1, (uint32_t)wsap_vtcore_hist_line_estimate(h, v->end_id - 1, cols));
for (uint64_t id = v->end_id; id < end; id++)
- set_count(v, id, (uint32_t)term_hist_line_estimate(h, id, cols));
+ set_count(v, id, (uint32_t)wsap_vtcore_hist_line_estimate(h, id, cols));
}
v->first_id = first;
v->end_id = end;
@@ -99,7 +99,7 @@ bool term_hist_view_sync(struct hist_view *v, const struct hist *h, int cols)
v->epoch = h->index_epoch;
v->head = h->head;
v->tail = h->tail;
- v->last_cells = h->lines ? term_hist_line_cells(h, end - 1) : 0;
+ v->last_cells = h->lines ? wsap_vtcore_hist_line_cells(h, end - 1) : 0;
return true;
}
@@ -110,14 +110,14 @@ static uint64_t anchor_extra(const struct hist_view *v, const struct hist *h, in
if (!v->anchor.active || id < hist_first_id(h) || id >= hist_end_id(h))
return 0;
uint64_t estimated = current(v, h, cols) ? v->counts[(uint32_t)id & (v->cap - 1)] :
- term_hist_line_estimate(h, id, cols);
- uint64_t exact = (uint64_t)term_hist_line_rows(h, id, cols);
+ wsap_vtcore_hist_line_estimate(h, id, cols);
+ uint64_t exact = (uint64_t)wsap_vtcore_hist_line_rows(h, id, cols);
return exact > estimated ? exact - estimated : 0;
}
-uint64_t term_hist_view_rows(const struct hist_view *v, const struct hist *h, int cols)
+uint64_t wsap_vtcore_hist_view_rows(const struct hist_view *v, const struct hist *h, int cols)
{
- uint64_t rows = current(v, h, cols) ? v->total_rows : term_hist_estimated_rows(h, cols);
+ uint64_t rows = current(v, h, cols) ? v->total_rows : wsap_vtcore_hist_estimated_rows(h, cols);
return rows + anchor_extra(v, h, cols);
}
@@ -149,7 +149,7 @@ static uint32_t select_slot(const struct hist_view *v, uint64_t row, int *seg)
return slot;
}
-bool term_hist_view_find_row(const struct hist_view *v, const struct hist *h, int row,
+bool wsap_vtcore_hist_view_find_row(const struct hist_view *v, const struct hist *h, int row,
int cols, uint64_t *id, int *seg)
{
if (!current(v, h, cols)) {
@@ -157,7 +157,7 @@ bool term_hist_view_find_row(const struct hist_view *v, const struct hist *h, in
return false;
uint64_t target = (uint64_t)row;
for (uint64_t line = hist_first_id(h); line < hist_end_id(h); line++) {
- uint64_t count = term_hist_line_estimate(h, line, cols);
+ uint64_t count = wsap_vtcore_hist_line_estimate(h, line, cols);
if (target < count) {
*id = line;
*seg = (int)target;
@@ -183,56 +183,56 @@ static int rows_as_int(uint64_t rows)
return rows > INT_MAX ? INT_MAX : (int)rows;
}
-int term_hist_view_scroll_offset(const struct hist_view *v, const struct hist *h, int cols)
+int wsap_vtcore_hist_view_scroll_offset(const struct hist_view *v, const struct hist *h, int cols)
{
if (!v->anchor.active || !h->lines)
return 0;
uint64_t id = v->anchor.line_id;
if (id < hist_first_id(h))
- return rows_as_int(term_hist_view_rows(v, h, cols));
+ return rows_as_int(wsap_vtcore_hist_view_rows(v, h, cols));
if (id >= hist_end_id(h))
return 0;
int seg = v->cols == cols ? (int)v->anchor.seg :
- term_hist_cell_segment(h, id, v->anchor.cell, cols);
+ wsap_vtcore_hist_cell_segment(h, id, v->anchor.cell, cols);
uint64_t rows = 0;
if (current(v, h, cols))
rows = v->total_rows - before(v, id);
else
for (; id < hist_end_id(h); id++)
- rows += term_hist_line_estimate(h, id, cols);
+ rows += wsap_vtcore_hist_line_estimate(h, id, cols);
rows += anchor_extra(v, h, cols);
return rows > (uint64_t)seg ? rows_as_int(rows - seg) : 0;
}
-void term_hist_view_note_push(struct hist_view *v, const struct hist *h, int cols)
+void wsap_vtcore_hist_view_note_push(struct hist_view *v, const struct hist *h, int cols)
{
if (!v->anchor.active)
return;
if (v->anchor.line_id < hist_first_id(h))
v->anchor = (struct view_anchor){ .line_id = hist_first_id(h), .active = true };
- uint64_t base = term_hist_segment_cell(h, v->anchor.line_id, 0, cols);
+ uint64_t base = wsap_vtcore_hist_segment_cell(h, v->anchor.line_id, 0, cols);
if (v->anchor.base_cell != base) {
if (v->anchor.cell < base)
v->anchor.cell = base;
- v->anchor.seg = (uint32_t)term_hist_cell_segment(h, v->anchor.line_id, v->anchor.cell, cols);
+ v->anchor.seg = (uint32_t)wsap_vtcore_hist_cell_segment(h, v->anchor.line_id, v->anchor.cell, cols);
v->anchor.base_cell = base;
}
}
-void term_hist_view_rewrap(struct hist_view *v, const struct hist *h, int cols)
+void wsap_vtcore_hist_view_rewrap(struct hist_view *v, const struct hist *h, int cols)
{
- term_hist_view_note_push(v, h, cols);
+ wsap_vtcore_hist_view_note_push(v, h, cols);
if (v->anchor.active) {
if (v->anchor.line_id >= hist_end_id(h))
v->anchor = (struct view_anchor){0};
else
- v->anchor.seg = (uint32_t)term_hist_cell_segment(h, v->anchor.line_id, v->anchor.cell, cols);
+ v->anchor.seg = (uint32_t)wsap_vtcore_hist_cell_segment(h, v->anchor.line_id, v->anchor.cell, cols);
}
v->cols = cols;
v->index_cols = 0;
}
-void term_hist_view_scroll_to(struct hist_view *v, const struct hist *h, int cols,
+void wsap_vtcore_hist_view_scroll_to(struct hist_view *v, const struct hist *h, int cols,
struct line_pos screen_top, int offset)
{
(void)screen_top;
@@ -241,22 +241,22 @@ void term_hist_view_scroll_to(struct hist_view *v, const struct hist *h, int col
return;
}
/* Allocation failure uses the read-only history walk. */
- uint64_t total = term_hist_view_rows(v, h, cols);
+ uint64_t total = wsap_vtcore_hist_view_rows(v, h, cols);
if ((uint64_t)offset > total)
offset = rows_as_int(total);
uint64_t id;
int seg;
uint64_t row = total - offset;
- if (row > INT_MAX || !term_hist_view_find_row(v, h, (int)row, cols, &id, &seg))
+ if (row > INT_MAX || !wsap_vtcore_hist_view_find_row(v, h, (int)row, cols, &id, &seg))
return;
v->anchor = (struct view_anchor){ .line_id = id, .seg = (uint32_t)seg,
- .cell = term_hist_segment_cell(h, id, seg, cols),
- .base_cell = term_hist_segment_cell(h, id, 0, cols), .active = true };
+ .cell = wsap_vtcore_hist_segment_cell(h, id, seg, cols),
+ .base_cell = wsap_vtcore_hist_segment_cell(h, id, 0, cols), .active = true };
v->cols = cols;
}
/* Relative movement visits only the logical lines it crosses. */
-void term_hist_view_scroll(struct hist_view *v, const struct hist *h, int cols,
+void wsap_vtcore_hist_view_scroll(struct hist_view *v, const struct hist *h, int cols,
struct line_pos screen_top, int lines)
{
(void)screen_top;
@@ -270,22 +270,22 @@ void term_hist_view_scroll(struct hist_view *v, const struct hist *h, int cols,
id = hist_first_id(h);
if (id >= hist_end_id(h))
id = hist_end_id(h) - 1;
- seg = v->cols == cols ? (int64_t)v->anchor.seg : term_hist_cell_segment(h, id, v->anchor.cell, cols);
+ seg = v->cols == cols ? (int64_t)v->anchor.seg : wsap_vtcore_hist_cell_segment(h, id, v->anchor.cell, cols);
} else {
if (lines < 0)
return;
id = hist_end_id(h) - 1;
- seg = term_hist_line_rows(h, id, cols);
+ seg = wsap_vtcore_hist_line_rows(h, id, cols);
}
seg -= (int64_t)lines;
if (lines > 0) {
while (seg < 0 && id > hist_first_id(h))
- seg += term_hist_line_rows(h, --id, cols);
+ seg += wsap_vtcore_hist_line_rows(h, --id, cols);
if (seg < 0)
seg = 0;
} else {
for (;;) {
- int count = term_hist_line_rows(h, id, cols);
+ int count = wsap_vtcore_hist_line_rows(h, id, cols);
if (seg < count)
break;
seg -= count;
@@ -296,13 +296,13 @@ void term_hist_view_scroll(struct hist_view *v, const struct hist *h, int cols,
}
}
v->anchor = (struct view_anchor){ .line_id = id, .seg = (uint32_t)seg,
- .cell = term_hist_segment_cell(h, id, (int)seg, cols),
- .base_cell = term_hist_segment_cell(h, id, 0, cols), .active = true };
+ .cell = wsap_vtcore_hist_segment_cell(h, id, (int)seg, cols),
+ .base_cell = wsap_vtcore_hist_segment_cell(h, id, 0, cols), .active = true };
v->cols = cols;
}
/* A viewport walks exact segments from its anchor, never an estimated row. */
-bool term_hist_view_row_pos(const struct hist_view *v, const struct hist *h, int cols,
+bool wsap_vtcore_hist_view_row_pos(const struct hist_view *v, const struct hist *h, int cols,
int screen_rows, struct line_pos screen_top, int y,
struct hist_view_pos *pos)
{
@@ -310,14 +310,14 @@ bool term_hist_view_row_pos(const struct hist_view *v, const struct hist *h, int
if (v->anchor.active && h->lines) {
uint64_t id = v->anchor.line_id;
int seg = v->cols == cols ? (int)v->anchor.seg :
- term_hist_cell_segment(h, id, v->anchor.cell, cols);
+ wsap_vtcore_hist_cell_segment(h, id, v->anchor.cell, cols);
if (id < hist_first_id(h)) {
id = hist_first_id(h);
seg = 0;
}
int64_t target = (int64_t)seg + y;
while (id < hist_end_id(h)) {
- int count = term_hist_line_rows(h, id, cols);
+ int count = wsap_vtcore_hist_line_rows(h, id, cols);
if (target < count) {
pos->id = id;
pos->seg = (int)target;
@@ -334,7 +334,7 @@ bool term_hist_view_row_pos(const struct hist_view *v, const struct hist *h, int
}
/* Wide line counts become exact when the viewport visits them. */
-void term_hist_view_refine(struct hist_view *v, struct hist *h, int cols, int rows)
+void wsap_vtcore_hist_view_refine(struct hist_view *v, struct hist *h, int cols, int rows)
{
if (!v->anchor.active || !current(v, h, cols))
return;
@@ -346,9 +346,9 @@ void term_hist_view_refine(struct hist_view *v, struct hist *h, int cols, int ro
seg = 0;
}
for (; id < hist_end_id(h) && remaining > 0; id++) {
- int count = term_hist_line_rows(h, id, cols);
+ int count = wsap_vtcore_hist_line_rows(h, id, cols);
set_count(v, id, (uint32_t)count);
- term_hist_refine_rows(h, id, cols, count);
+ wsap_vtcore_hist_refine_rows(h, id, cols, count);
remaining -= count - seg;
seg = 0;
}