Skip to content

Commit 9b67ddb

Browse files
authored
Merge pull request #25 from koki-develop/feature/size-setting
2 parents f2e07d1 + 87a9db0 commit 9b67ddb

File tree

8 files changed

+137
-0
lines changed

8 files changed

+137
-0
lines changed

README.ja.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ actions:
280280
- [`defaultSpeed`](#defaultspeed) - デフォルトの入力速度。
281281
- [`browserBin`](#browserbin) - ブラウザの実行可能なバイナリへのパス。
282282
- [`skipPauseBeforeQuit`](#skippausebeforequit) - 終了前の一時停止をスキップ。
283+
- [`width`](#width) - ウィンドウの幅。
284+
- [`height`](#height) - ウィンドウの高さ。
283285

284286
#### `loginCommand`
285287

@@ -346,6 +348,26 @@ settings:
346348
skipPauseBeforeQuit: true
347349
```
348350

351+
#### `width`
352+
353+
ウィンドウの幅。
354+
355+
```yaml
356+
# e.g.
357+
settings:
358+
width: 1600
359+
```
360+
361+
#### `height`
362+
363+
ウィンドウの高さ。
364+
365+
```yaml
366+
# e.g.
367+
settings:
368+
height: 800
369+
```
370+
349371
## :book: サンプル
350372

351373
それ以外のサンプルについては [`examples/`](./examples/) ディレクトリを参照してください。

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ Available settings:
283283
- [`defaultSpeed`](#defaultspeed) - Default interval between key typing.
284284
- [`browserBin`](#browserbin) - Path to executable browser binary.
285285
- [`skipPauseBeforeQuit`](#skippausebeforequit) - Skip pause before quitting.
286+
- [`width`](#width) - Window width.
287+
- [`height`](#height) - Window height.
286288

287289
#### `loginCommand`
288290

@@ -349,6 +351,26 @@ settings:
349351
skipPauseBeforeQuit: true
350352
```
351353

354+
#### `width`
355+
356+
Window width.
357+
358+
```yaml
359+
# e.g.
360+
settings:
361+
width: 1600
362+
```
363+
364+
#### `height`
365+
366+
Window height.
367+
368+
```yaml
369+
# e.g.
370+
settings:
371+
height: 800
372+
```
373+
352374
## :book: Examples
353375

354376
For more examples see the [`examples/`](./examples/) directory.

pkg/config/config_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ actions:
2828
DefaultSpeed: 10,
2929
BrowserBin: nil,
3030
SkipPauseBeforeQuit: false,
31+
Width: nil,
32+
Height: nil,
3133
},
3234
Actions: []Action{
3335
&PauseAction{},
@@ -45,6 +47,8 @@ settings:
4547
defaultSpeed: 200
4648
browserBin: BROWSER_BIN
4749
skipPauseBeforeQuit: true
50+
width: 1600
51+
height: 800
4852
actions:
4953
- pause
5054
`,
@@ -56,6 +60,8 @@ actions:
5660
DefaultSpeed: 200,
5761
BrowserBin: util.String("BROWSER_BIN"),
5862
SkipPauseBeforeQuit: true,
63+
Width: util.Int(1600),
64+
Height: util.Int(800),
5965
},
6066
Actions: []Action{
6167
&PauseAction{},
@@ -90,6 +96,8 @@ actions:
9096
DefaultSpeed: 10,
9197
BrowserBin: nil,
9298
SkipPauseBeforeQuit: false,
99+
Width: nil,
100+
Height: nil,
93101
},
94102
Actions: []Action{
95103
&TypeAction{Type: "Hello", Count: 1, Speed: 10},
@@ -166,6 +174,8 @@ func TestDecodeMap(t *testing.T) {
166174
DefaultSpeed: 10,
167175
BrowserBin: nil,
168176
SkipPauseBeforeQuit: false,
177+
Width: nil,
178+
Height: nil,
169179
},
170180
Actions: []Action{
171181
&PauseAction{},
@@ -182,6 +192,8 @@ func TestDecodeMap(t *testing.T) {
182192
"defaultSpeed": 200,
183193
"browserBin": "BROWSER_BIN",
184194
"skipPauseBeforeQuit": true,
195+
"width": 1600,
196+
"height": 800,
185197
},
186198
"actions": []interface{}{"pause"},
187199
},
@@ -193,6 +205,8 @@ func TestDecodeMap(t *testing.T) {
193205
DefaultSpeed: 200,
194206
BrowserBin: util.String("BROWSER_BIN"),
195207
SkipPauseBeforeQuit: true,
208+
Width: util.Int(1600),
209+
Height: util.Int(800),
196210
},
197211
Actions: []Action{
198212
&PauseAction{},
@@ -221,6 +235,8 @@ func TestDecodeMap(t *testing.T) {
221235
FontFamily: nil,
222236
DefaultSpeed: 10,
223237
BrowserBin: nil,
238+
Width: nil,
239+
Height: nil,
224240
},
225241
Actions: []Action{
226242
&TypeAction{Type: "Hello", Count: 1, Speed: 10},

pkg/config/settings.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ type Settings struct {
1313
DefaultSpeed int `mapstructure:"defaultSpeed"`
1414
BrowserBin *string `mapstructure:"browserBin"`
1515
SkipPauseBeforeQuit bool `mapstructure:"skipPauseBeforeQuit"`
16+
Width *int `mapstructure:"width"`
17+
Height *int `mapstructre:"height"`
1618
}
1719

1820
var settingsFields = []string{
@@ -22,6 +24,8 @@ var settingsFields = []string{
2224
"defaultSpeed",
2325
"browserBin",
2426
"skipPauseBeforeQuit",
27+
"width",
28+
"height",
2529
}
2630

2731
func DecodeSettings(m map[string]interface{}) (*Settings, error) {
@@ -32,6 +36,8 @@ func DecodeSettings(m map[string]interface{}) (*Settings, error) {
3236
DefaultSpeed: 10,
3337
BrowserBin: nil,
3438
SkipPauseBeforeQuit: false,
39+
Width: nil,
40+
Height: nil,
3541
}
3642
if m == nil {
3743
return &stgs, nil

pkg/config/settings_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ func TestDecodeSettings(t *testing.T) {
2323
DefaultSpeed: 10,
2424
BrowserBin: nil,
2525
SkipPauseBeforeQuit: false,
26+
Width: nil,
27+
Height: nil,
2628
},
2729
false,
2830
},
@@ -35,6 +37,8 @@ func TestDecodeSettings(t *testing.T) {
3537
DefaultSpeed: 10,
3638
BrowserBin: nil,
3739
SkipPauseBeforeQuit: false,
40+
Width: nil,
41+
Height: nil,
3842
},
3943
false,
4044
},
@@ -49,6 +53,8 @@ func TestDecodeSettings(t *testing.T) {
4953
DefaultSpeed: 10,
5054
BrowserBin: nil,
5155
SkipPauseBeforeQuit: false,
56+
Width: nil,
57+
Height: nil,
5258
},
5359
false,
5460
},
@@ -63,6 +69,8 @@ func TestDecodeSettings(t *testing.T) {
6369
DefaultSpeed: 10,
6470
BrowserBin: nil,
6571
SkipPauseBeforeQuit: false,
72+
Width: nil,
73+
Height: nil,
6674
},
6775
false,
6876
},
@@ -77,6 +85,8 @@ func TestDecodeSettings(t *testing.T) {
7785
DefaultSpeed: 10,
7886
BrowserBin: nil,
7987
SkipPauseBeforeQuit: false,
88+
Width: nil,
89+
Height: nil,
8090
},
8191
false,
8292
},
@@ -91,6 +101,8 @@ func TestDecodeSettings(t *testing.T) {
91101
DefaultSpeed: 200,
92102
BrowserBin: nil,
93103
SkipPauseBeforeQuit: false,
104+
Width: nil,
105+
Height: nil,
94106
},
95107
false,
96108
},
@@ -105,6 +117,8 @@ func TestDecodeSettings(t *testing.T) {
105117
DefaultSpeed: 10,
106118
BrowserBin: util.String("BROWSER_BIN"),
107119
SkipPauseBeforeQuit: false,
120+
Width: nil,
121+
Height: nil,
108122
},
109123
false,
110124
},
@@ -119,6 +133,40 @@ func TestDecodeSettings(t *testing.T) {
119133
DefaultSpeed: 10,
120134
BrowserBin: nil,
121135
SkipPauseBeforeQuit: true,
136+
Width: nil,
137+
Height: nil,
138+
},
139+
false,
140+
},
141+
{
142+
map[string]interface{}{
143+
"width": 2000,
144+
},
145+
&Settings{
146+
LoginCommand: []string{"bash", "--login"},
147+
FontSize: 22,
148+
FontFamily: nil,
149+
DefaultSpeed: 10,
150+
BrowserBin: nil,
151+
SkipPauseBeforeQuit: false,
152+
Width: util.Int(2000),
153+
Height: nil,
154+
},
155+
false,
156+
},
157+
{
158+
map[string]interface{}{
159+
"height": 1000,
160+
},
161+
&Settings{
162+
LoginCommand: []string{"bash", "--login"},
163+
FontSize: 22,
164+
FontFamily: nil,
165+
DefaultSpeed: 10,
166+
BrowserBin: nil,
167+
SkipPauseBeforeQuit: false,
168+
Width: nil,
169+
Height: util.Int(1000),
122170
},
123171
false,
124172
},
@@ -130,6 +178,8 @@ func TestDecodeSettings(t *testing.T) {
130178
"defaultSpeed": 200,
131179
"browserBin": "BROWSER_BIN",
132180
"skipPauseBeforeQuit": true,
181+
"width": 2000,
182+
"height": 1000,
133183
},
134184
&Settings{
135185
LoginCommand: []string{"zsh", "--login"},
@@ -138,6 +188,8 @@ func TestDecodeSettings(t *testing.T) {
138188
DefaultSpeed: 200,
139189
BrowserBin: util.String("BROWSER_BIN"),
140190
SkipPauseBeforeQuit: true,
191+
Width: util.Int(2000),
192+
Height: util.Int(1000),
141193
},
142194
false,
143195
},
@@ -156,6 +208,8 @@ func TestDecodeSettings(t *testing.T) {
156208
"defaultSpeed": 200,
157209
"browserBin": "BROWSER_BIN",
158210
"skipPauseBeforeQuit": true,
211+
"width": 2000,
212+
"height": 1000,
159213
"a": "A",
160214
},
161215
nil,

pkg/ui/update.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
tea "github.com/charmbracelet/bubbletea"
99
"github.com/go-rod/rod"
1010
"github.com/go-rod/rod/lib/input"
11+
"github.com/go-rod/rod/lib/proto"
1112
"github.com/koki-develop/clive/pkg/browser"
1213
"github.com/koki-develop/clive/pkg/config"
1314
"github.com/koki-develop/clive/pkg/ttyd"
@@ -126,6 +127,13 @@ func (m *Model) openPage() (*rod.Page, error) {
126127
}
127128

128129
func (m *Model) setupPage(page *rod.Page) error {
130+
// window size
131+
if m.config.Settings.Width != nil || m.config.Settings.Height != nil {
132+
if err := page.SetWindow(&proto.BrowserBounds{Width: m.config.Settings.Width, Height: m.config.Settings.Height}); err != nil {
133+
return err
134+
}
135+
}
136+
129137
// font family
130138
if m.config.Settings.FontFamily != nil {
131139
if _, err := page.Eval(fmt.Sprintf("() => term.options.fontFamily = '%s'", *m.config.Settings.FontFamily)); err != nil {

pkg/util/int.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ func Max(x, y int) int {
1212
func Digits(n int) int {
1313
return len(strconv.Itoa(n))
1414
}
15+
16+
func Int(v int) *int {
17+
return &v
18+
}

pkg/util/int_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,8 @@ func TestDigits(t *testing.T) {
8181
})
8282
}
8383
}
84+
85+
func TestInt(t *testing.T) {
86+
i := 1
87+
assert.Equal(t, &i, Int(i))
88+
}

0 commit comments

Comments
 (0)