-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli.c
More file actions
107 lines (83 loc) · 3.38 KB
/
cli.c
File metadata and controls
107 lines (83 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <external.h>
#include "buildeka_module.h"
status BuildCli_RenderStatus(MemCh *m, void *a){
CliStatus *cli = (CliStatus *)Ifc(m, a, TYPE_CLI_STATUS);
BuildCtx *ctx = (BuildCtx *)Ifc(m, cli->source, TYPE_BUILDCTX);
i32 width = ctx->cli.cli->cols;
float total = (float)ctx->input.totalSources->val.i;
float count = (float)ctx->input.countSources->val.i;
float colsFloat = (float)width;
float progress = ceil((count/total) * colsFloat);
ctx->cli.fields.steps.barStart->length = (i32)progress;
MemBookStats st;
MemBook_GetStats(m, &st);
CliStatus_SetByKey(m, cli, Str_CstrRef(m, "memTotal"),
Str_MemCount(ctx->m, st.total*PAGE_SIZE));
Single *sg = (Single *)Ifc(m, CliStatus_GetByKey(m,
cli, Str_CstrRef(m, "chapters")), TYPE_WRAPPED_I64);
sg->val.value = st.total;
sg = (Single *)Ifc(m, CliStatus_GetByKey(m,
cli, Str_CstrRef(m, "chaptersTotal")), TYPE_WRAPPED_I64);
sg->val.value = st.pageIdx;
return SUCCESS;
}
status BuildCli_SetupComplete(BuildCtx *ctx){
FmtLine *ln = Span_Get(ctx->cli.cli->lines, 0);
ln->fmt = "^g.Completed ^D.$^d. sources^0.";
ln->args = Arr_Make(ctx->m, 2);
ln->args[0] = ctx->input.totalSources;
ln = Span_Get(ctx->cli.cli->lines, 1);
ln->fmt = "^g.Sources ^D.$^d.^0.";
ln = Span_Get(ctx->cli.cli->lines, 2);
ctx->cli.fields.steps.barStart->length = ctx->cli.cli->cols;
ln->fmt = "^G.$^0.";
ln = Span_Get(ctx->cli.cli->lines, 3);
ln->args[0] = Str_Ref(ctx->m, (byte *)"g.", 2, 3, STRING_FMT_ANSI);
return SUCCESS;
}
status BuildCli_SetupStatus(BuildCtx *ctx){
MemCh *m = ctx->m;
Span *lines = ctx->cli.cli->lines;
memset(&ctx->cli.fields, 0, sizeof(ctx->cli.fields));
CliStatus_SetDims(ctx->cli.cli, 0, 0);
i32 width = ctx->cli.cli->cols;
IntPair coords = {0, 0};
void **arr = NULL;
arr = Arr_Make(m, 2);
arr[0] = ctx->input.countSources;
arr[1] = ctx->input.totalSources;
Span_Add(ctx->cli.cli->lines,
FmtLine_Make(m, "^y.Source $ of $^0", arr));
ctx->cli.fields.current[4] = NULL;
Span_Add(ctx->cli.cli->lines,
FmtLine_Make(m, "^y.Building $ $ $", ctx->cli.fields.current));
ctx->cli.fields.steps.barStart = Str_Make(m, width);
memset(ctx->cli.fields.steps.barStart->bytes, ' ', width);
ctx->cli.fields.steps.barStart->length = width;
ctx->cli.fields.steps.barLead = Str_CloneAlloc(m,
ctx->cli.fields.steps.barStart, width);
ctx->cli.fields.steps.barStart->length = 0;
ctx->cli.fields.steps.barLead->length = 0;
arr = Arr_Make(m, 2);
arr[0] = ctx->cli.fields.steps.barStart;
arr[1] = ctx->cli.fields.steps.barLead;
Span_Add(ctx->cli.cli->lines,
FmtLine_Make(m, "^B.$^0.^Y.$^0", arr));
arr = Arr_Make(m, 5);
arr[0] = NULL;
arr[1] = I64_Wrapped(m, 0);
arr[2] = I64_Wrapped(m, 0);
arr[3] = I64_Wrapped(m, PAGE_SIZE);
arr[4] = NULL;
Span_Add(ctx->cli.cli->lines,
FmtLine_Make(m,
"^c.Memory $ total/maxIdx=^D.$/$^d. page-size=$b^0", arr));
coords.a = ctx->cli.cli->lines->max_idx;
coords.b = 0;
CliStatus_SetKey(m, ctx->cli.cli, Str_CstrRef(m, "memTotal"), &coords);
coords.b = 1;
CliStatus_SetKey(m, ctx->cli.cli, Str_CstrRef(m, "chapters"), &coords);
coords.b = 2;
CliStatus_SetKey(m, ctx->cli.cli, Str_CstrRef(m, "chaptersTotal"), &coords);
return SUCCESS;
}