-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
inv2004
committed
Nov 27, 2022
1 parent
a985774
commit 08634a9
Showing
4 changed files
with
92 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
import ttop/tui | ||
import ttop/save | ||
|
||
import os | ||
|
||
proc isSave(): bool = | ||
if paramCount() >= 1 and paramStr(1) == "-s": | ||
true | ||
elif getAppFilename().extractFilename() == "ttop": | ||
false | ||
else: | ||
false | ||
|
||
proc main() = | ||
run() | ||
if isSave(): | ||
save() | ||
else: | ||
run() | ||
|
||
when isMainModule: | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import procfs | ||
import marshal | ||
import zippy | ||
import streams | ||
|
||
const blog = "/tmp/1.blog" | ||
|
||
proc count*(): int = | ||
let s = newFileStream(blog, fmRead) | ||
if s == nil: | ||
return | ||
while not s.atEnd(): | ||
let sz = s.readUInt32() | ||
discard s.readStr(int(sz)) | ||
discard s.readUInt32() | ||
inc result | ||
|
||
proc save*() = | ||
let info = fullInfo() | ||
let buf = compress($$info) | ||
let s = newFileStream(blog, fmAppend) | ||
s.write buf.len.uint32 | ||
s.write buf | ||
s.write buf.len.uint32 | ||
s.close() | ||
|
||
proc hist*(ii: int): FullInfo = | ||
let f = open(blog, fmRead) | ||
defer: f.close() | ||
let s = newFileStream(f) | ||
s.setPosition(f.getFileSize().int) | ||
for i in 1..ii: | ||
if s.getPosition() - 4 < 0: | ||
return | ||
s.setPosition(s.getPosition().int - 4) | ||
let sz = s.readUInt32.int | ||
s.setPosition(s.getPosition().int - 8 - sz) | ||
|
||
let sz = s.readUInt32.int | ||
let buf = s.readStr(sz) | ||
to[FullInfo](uncompress(buf)) | ||
|
||
when isMainModule: | ||
echo count() | ||
echo hist(6) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters