-
Notifications
You must be signed in to change notification settings - Fork 0
/
uptime.fls
81 lines (60 loc) · 2.26 KB
/
uptime.fls
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
//
// MIT License
//
// Copyright (c) 2020 Ferhat Geçdoğan All Rights Reserved.
// Distributed under the terms of the MIT License.
//
//
// FlaScript utils - uptime.fls
//
// * This program prints current uptime as hour(s) - minute(s)
//
// TODO: Get days value from /proc/uptime
//
// Check version of FlaScript (Fla-Utils required latest version)
except(version) : 0.3 -> { error("Install latest version of FlaScript") } version;
main() -> main {
// Create data as null string
// Create hours and minutes as null integer
// -------------------------------------
// FlaScript allows you to convert automatically string to integer without type a function,
// * Note: In FlaScript all variables collected as string, when you want to use it as integer, it converts automatically.
// * So, integer type is not really collected as integer,
// * It's string but when you use this variable, FlaScript forces to convert it to integer.
var(string) -> null -> data <-
var(int) -> null -> hours <-
var(int) -> null -> minutes <-
// Some color definitions
var(string) -> \033[1;96m -> bold_light_cyan <-
var(string) -> \033[1;34m -> bold_blue <-
var(string) -> \033[1;95m -> bold_light_magenta <-
var(string) -> \033[1;35m -> bold_magenta <-
var(string) -> \033[0m -> reset <-
// We will convert hours and minutes variables to str_hour and str_minute
// with ANSI Color escape sequences.
var(string) -> null -> str_hour <-
var(string) -> null -> str_minute <-
// Read file with return.
@readfile -> data -> "/proc/uptime" <
// Divide data by 60 and equal returned
// value to hours and minutes
@data /= 60 -> var(hours) <
@data /= 60 -> var(minutes) <
// Divide hours by 60
// Then, get modulo(24) and equalize to it.
@hours /= 60 <
@hours %= 24 <
@minutes %= 60 <
// Equalize the str_hour and str_minute value to unparsed
// color definitions
@equal -> str_hour -> {bold_light_cyan}{hours}{bold_blue}h <
@equal -> str_minute -> {bold_light_magenta}{minutes}{bold_magenta}m\n{reset} <
// replace colors
@escape_seq -> str_hour <
// parse colors
@escape_seq -> str_hour <
@escape_seq -> str_minute <
@escape_seq -> str_minute <
// print built-in function supports escape sequences
print(string) -> "{str_hour} {str_minute}"
} main;