Skip to content

Commit b7effe2

Browse files
committed
Statusline visiblity: Use options instead of mode variable
This simplifies the code and provides a proper interface to the user.
1 parent 035c4b6 commit b7effe2

File tree

3 files changed

+42
-68
lines changed

3 files changed

+42
-68
lines changed

common/content/events.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ const Events = Module("events", {
11821182
this._fullscreen = window.fullScreen;
11831183
liberator.triggerObserver("fullscreen", this._fullscreen);
11841184
autocommands.trigger("Fullscreen", { state: this._fullscreen });
1185-
statusline.setVisibility(statusline.setVisibility.EVENT_FULLSCREEN);
1185+
statusline.setVisibility(statusline.setVisibility.UPDATE);
11861186
}
11871187
}
11881188
}, {

common/content/modes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const Modes = Module("modes", {
104104
if (oldExtended & modes.HINTS)
105105
hints.hide();
106106
commandline.close();
107-
statusline.setVisibility(statusline.setVisibility.EVENT_HIDE);
107+
statusline.setVisibility(statusline.setVisibility.HIDE);
108108
break;
109109
}
110110

@@ -122,7 +122,7 @@ const Modes = Module("modes", {
122122
}
123123

124124
if (newMode == modes.COMMAND_LINE) {
125-
statusline.setVisibility(statusline.setVisibility.EVENT_SHOW);
125+
statusline.setVisibility(statusline.setVisibility.SHOW);
126126
}
127127

128128
},

common/content/statusline.js

Lines changed: 39 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -127,32 +127,12 @@ const StatusLine = Module("statusline", {
127127

128128
// set the visibility of the statusline
129129
setVisibility: function (request) {
130-
if ( typeof this.setVisibility.MODE_AUTO == 'undefined' ) { // TODO proper initialization
131-
/*
132-
* There are three modes:
133-
*
134-
* AUTO: This shows or hides the statusline depending on the fullscreen state.
135-
* ON: Here the statusline is always visible, even in fullscreen.
136-
* OFF: The statusline is hidden, only the commandline is shown after typing a colon.
137-
*/
138-
this.setVisibility.MODE_AUTO = 0;
139-
this.setVisibility.MODE_ON = 1;
140-
this.setVisibility.MODE_OFF = 2;
141-
142-
/*
143-
* Several events can happen:
144-
*
145-
* FULLSCREEN: Whenever the fullscreen state changes.
146-
* TOGGLE: Cycles through all three modes. Currently there's no indicator, so it's not easy with three modes instead of two.
147-
* SHOW and HIDE: These are emitted when entering or leaving the commandline.
148-
*/
149-
this.setVisibility.EVENT_TOGGLE = 3;
150-
this.setVisibility.EVENT_FULLSCREEN = 4;
151-
this.setVisibility.EVENT_SHOW = 5;
152-
this.setVisibility.EVENT_HIDE = 6;
130+
if ( typeof this.setVisibility.UPDATE == 'undefined' ) { // TODO proper initialization
131+
this.setVisibility.UPDATE = 0; // Apply current configuration
132+
this.setVisibility.SHOW = 1; // Temporarily show statusline
133+
this.setVisibility.HIDE = 2; // Temporarily hide statusline
153134

154135
this.setVisibility.contentSeparator = highlight.get('ContentSeparator').value;
155-
this.setVisibility.mode = this.setVisibility.MODE_AUTO;
156136
this.setVisibility.isVisible = true;
157137
}
158138

@@ -186,57 +166,34 @@ const StatusLine = Module("statusline", {
186166
sv.isVisible = true;
187167
};
188168

189-
switch (request) {
190-
case sv.MODE_AUTO:
191-
sv.mode = sv.MODE_AUTO;
192-
statusline.setVisibility(sv.EVENT_FULLSCREEN);
193-
break;
194-
195-
case sv.MODE_ON:
196-
sv.mode = sv.MODE_ON;
197-
showStatusline();
198-
break;
199-
200-
case sv.MODE_OFF:
201-
sv.mode = sv.MODE_OFF;
202-
hideStatusline();
203-
break;
204-
205-
case sv.EVENT_FULLSCREEN:
206-
// Ignore fullscreen event if we are not in AUTO mode, visiblity was set manually.
207-
if (sv.mode != sv.MODE_AUTO) {
208-
break;
209-
}
169+
let mode = options["statuslinevisibility"];
210170

211-
if (window.fullScreen) {
212-
hideStatusline();
213-
} else {
214-
showStatusline();
215-
}
216-
break;
217-
218-
case sv.EVENT_TOGGLE:
219-
// Cycle through all available modes.
220-
switch (sv.mode) {
221-
case sv.MODE_AUTO:
222-
statusline.setVisibility(sv.MODE_ON);
171+
switch (request) {
172+
case sv.UPDATE:
173+
switch (mode) {
174+
case "auto":
175+
if (window.fullScreen) {
176+
hideStatusline();
177+
} else {
178+
showStatusline();
179+
}
223180
break;
224-
case sv.MODE_ON:
225-
statusline.setVisibility(sv.MODE_OFF);
181+
case "visible":
182+
showStatusline();
226183
break;
227-
case sv.MODE_OFF:
228-
statusline.setVisibility(sv.MODE_AUTO);
184+
case "hidden":
185+
hideStatusline();
229186
break;
230187
}
231188
break;
232189

233-
case sv.EVENT_SHOW:
190+
case sv.SHOW:
234191
showStatusline();
235192
break;
236193

237-
case sv.EVENT_HIDE:
238-
// Only hide when in AUTO+fullscreen or OFF.
239-
if ((sv.mode == sv.MODE_AUTO && window.fullScreen) || sv.mode == sv.MODE_OFF) {
194+
case sv.HIDE:
195+
// Only hide when in auto+fullscreen or hidden.
196+
if ((mode == "auto" && window.fullScreen) || mode == "hidden") {
240197
hideStatusline();
241198
}
242199
break;
@@ -442,6 +399,23 @@ const StatusLine = Module("statusline", {
442399
return [[name, fields[name].description] for (name of Object.keys(fields))];
443400
},
444401
});
402+
403+
options.add(["statuslinevisibility", "slv"],
404+
"Control the visibility of the statusline",
405+
"string", "auto",
406+
{
407+
setter: function setter(value) {
408+
statusline.setVisibility(statusline.setVisibility.UPDATE);
409+
return value;
410+
},
411+
completer: function completer(context) {
412+
return [
413+
["auto", "Hide statusline in fullscreen automatically"],
414+
["visible", "Always show the statusline"],
415+
["hidden", "Never show the statusline"]
416+
];
417+
},
418+
});
445419
}
446420
});
447421

0 commit comments

Comments
 (0)