Repository navigation
Expand file tree
/
Copy pathmain.odin
More file actions
135 lines (112 loc) · 2.6 KB
/
Copy pathmain.odin
File metadata and controls
135 lines (112 loc) · 2.6 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package diff_view
import "core:fmt"
import "core:log"
import "core:mem"
import "core:os"
import "input"
import "render"
Run_Mode :: enum {
Server,
UI,
}
main :: proc() {
context.logger = log.create_console_logger(.Info)
root_path, session_name, mode, args_ok := parse_args()
if !args_ok {
return
}
switch mode {
case .Server:
session, err := session_create(root_path, session_name)
if err != nil {
log.errorf("Failed to create session: %v", err)
return
}
log.infof("diff_view watching: %s (session: %s)", session.root_path, session.session_name)
session_run(session)
session_destroy(session)
log.info("Session ended.")
case .UI:
gfx: Gfx_State
if !gfx_init(&gfx) {
return
}
defer gfx_shutdown(&gfx)
if !gfx_window_open(&gfx, 1280, 800, "diff_view") {
return
}
rs: render.Render_State
if !render.init(&rs) {
return
}
app: App
if !app_init(&app, &rs, root_path, gfx.window) {
render.destroy(&rs)
return
}
inp := input.init(gfx.window)
defer input.destroy(inp)
// Enable re-rendering during window resize on macOS.
frame_ctx := Frame_Context{
gfx = &gfx,
rs = &rs,
app = &app,
inp = inp,
}
gfx_set_refresh_context(&frame_ctx)
gfx_install_refresh_callback(&gfx)
for !inp.should_quit {
mem.free_all(context.temp_allocator)
input.update(inp)
gfx_frame_begin(&gfx)
render.clear_screen(18.0/255, 18.0/255, 22.0/255, 1.0)
app_render(&app, &rs, inp, gfx.dpi_scale)
gfx_frame_end(&gfx)
}
app_exit(&app)
render.destroy(&rs)
}
}
parse_args :: proc() -> (root_path: string, session_name: string, mode: Run_Mode, ok: bool) {
args := os.args[1:]
if len(args) < 1 {
_print_usage()
return "", "", .Server, false
}
has_mode := false
for arg in args {
if arg == "-server" {
mode = .Server
has_mode = true
} else if arg == "-ui" {
mode = .UI
has_mode = true
} else if len(arg) > 9 && arg[:9] == "-session=" {
session_name = arg[9:]
} else if arg[0] == '-' {
fmt.eprintfln("Unknown flag: %s", arg)
_print_usage()
return "", "", .Server, false
} else {
root_path = arg
}
}
if !has_mode {
_print_usage()
return "", "", .Server, false
}
if len(root_path) == 0 {
fmt.eprintln("Error: no directory specified")
_print_usage()
return "", "", .Server, false
}
if !os.is_dir(root_path) {
fmt.eprintfln("Error: '%s' is not a directory", root_path)
return "", "", .Server, false
}
return root_path, session_name, mode, true
}
_print_usage :: proc() {
fmt.eprintln("Usage: diff_view -server <directory> [-session=<name>]")
fmt.eprintln(" diff_view -ui <directory>")
}