OSDN Git Service

[add] : 記事投稿スクリプトをVで書き直す
[alterlinux/hayao.fascode.net.git] / blog / new-post.v
1 import os
2 import ui
3 //import eventbus
4
5 const (
6         win_width  = 300
7         win_height = 150
8 )
9
10 struct App {
11         mut:
12                 window       &ui.Window = 0
13                 first_ipsum  string
14                 second_ipsum string
15                 full_name    string
16 }
17
18 fn main(){
19         // Check environment
20         check_system_env()
21
22         mut app := &App{}
23         app.window = ui.window(
24                 width: win_width
25                 height: win_height
26                 mode: .resizable
27                 on_resize: fn (width int, height int, win &ui.Window){
28                         // ウィンドウリサイズ時の処理
29                 }
30                 title: "ブログの新規記事の作成"
31                 state: app
32                 children: [
33                         ui.column(
34                                 id: "main"
35                                 width: int(ui.stretch)
36                                 alignment: .center
37                                 //spacing: 2
38                                 margin_: 5
39                                 children: [
40                                         ui.row(
41                                                 //height: 20
42                                                 id: "group_url"
43                                                 widths: ui.stretch
44                                                 heights: ui.stretch
45                                                 children: [
46                                                         ui.label(
47                                                                 id: "url_label"
48                                                                 text: "Please enter URL"
49                                                         )
50                                                         ui.textbox(
51                                                                         id: "url_tb"
52                                                                         read_only: false
53                                                                         //min: 1
54                                                                         max_len: 20
55                                                                         width: 250
56                                                         )
57                                                 ]
58                                         )
59                                         ui.row(
60                                                 //height: 10
61                                                 id: "group_title"
62                                                 widths: ui.stretch
63                                                 heights: ui.stretch
64                                                 children: [
65                                                         ui.label(
66                                                                 id: "title_label"
67                                                                 text: "Please enter the title"
68                                                         )
69                                                         ui.textbox(
70                                                                 id: "title_tb"
71                                                                 read_only: false
72                                                                 max_len: 20
73                                                                 width: 250
74                                                         )
75                                                 ]
76                                         )
77                                         ui.column(
78                                                 id: "group_create"
79                                                 widths: ui.stretch
80                                                 heights: ui.stretch
81                                                 children: [
82                                                         ui.column(
83                                                                 //spacing: 2
84                                                                 margin_: 5
85                                                                 //alignment: .center
86                                                                 children: [
87                                                                         ui.button(
88                                                                                 height: 10
89                                                                                 id: "exit_btn"
90                                                                                 text: "Exit"
91                                                                                 radius: .0
92                                                                                 onclick: fn(_ voidptr, b &ui.Button){
93                                                                                         exit(0)
94                                                                                 }
95                                                                         )
96                                                                         ui.button(
97                                                                                 height: 10
98                                                                                 id: 'create_btn'
99                                                                                 text: 'Create new article'
100                                                                                 //width: ui.stretch
101                                                                                 radius: .0
102                                                                                 onclick: fn(_ voidptr, b &ui.Button){
103                                                                                         create_article()
104                                                                                 }
105                                                                         )
106                                                                 ]
107                                                         )
108                                                 ]
109                                         )
110                                 ]
111                         )
112                 ]
113         )
114         ui.run(app.window)
115 }
116
117 fn create_article(){
118         eprintln("まだ実装されてないンゴ")
119         exit(0)
120 }
121
122 fn cmd_available(c string) bool{
123         mut cmd := ""
124         $if windows{
125                 cmd = "WHERE"
126         }$else{
127                 cmd = "type"
128         }
129
130         result := os.execute("${cmd} \"${c}\"")
131         return result.exit_code == 0
132 }
133
134 fn check_system_env(){
135         mut check := 0
136         if ! cmd_available("hugo"){
137                 eprintln("Hugo command was not found on this computer.")
138                 check++
139         }
140
141         if check != 0{
142                 exit(1)
143         }
144         return
145 }