Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize the selection menu. #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ var DLNA_Browser = function(options) {
DLNA_Browser.prototype.findDLNAServers = function() {
this.scan = false;
this.menu.title = "Scanning for DLNA Servers";
this.menu.renderMenu("", 1);
this.menu.renderMenu(null, 1);


mp.msg.info("scanning for dlna servers");
Expand Down Expand Up @@ -330,7 +330,7 @@ DLNA_Browser.prototype.findDLNAServers = function() {
this.current_folder = this.servers;
this.menu.setOptions(this.servers, 0);

this.menu.renderMenu("", 1);
this.menu.renderMenu(null, 1);
};


Expand Down Expand Up @@ -846,7 +846,7 @@ DLNA_Browser.prototype.autocomplete_text = function(text, message, tabbing) {

// Update the menu selection to match
this.menu.selectionIdx = this.selected_auto.findex;
this.menu.renderMenu("", 1);
this.menu.renderMenu(null, 1);

message = Ass.alpha("DDDD6E") + this.selected_auto.pre
+ Ass.alpha("00") + message + Ass.alpha("DDDD6E") + this.selected_auto.post;
Expand Down Expand Up @@ -950,7 +950,7 @@ DLNA_Browser.prototype.command_ep = function(args, text) {
if (episode_info.start <= s_target && s_target <= episode_info.end) {
this.select(selection.children[i]);
this.menu.selectionIdx = j;
this.menu.renderMenu("", 1);
this.menu.renderMenu(null, 1);

// Make the output look nice
var E = episode_info.start;
Expand Down Expand Up @@ -1051,7 +1051,7 @@ DLNA_Browser.prototype.on_file_load = function() {

// Update the now playing indicator and rerender the menu if necessary
folder[episode.id].isPlaying = true;
this.menu.renderMenu("", 1);
this.menu.renderMenu(null, 1);

// Set the title to match the current episode
mp.msg.trace("setting title to: " + episode.folder.name + ": " + folder[episode.id].name);
Expand Down Expand Up @@ -1234,7 +1234,7 @@ DLNA_Browser.prototype.select = function(selection) {
success = true;
}

this.menu.renderMenu("", 1);
this.menu.renderMenu(null, 1);
return success;
}

Expand Down Expand Up @@ -1311,7 +1311,7 @@ DLNA_Browser.prototype.back = function() {
this.generateMenuTitle(this.titles[this.titles.length-1]);
}

this.menu.renderMenu("", 1);
this.menu.renderMenu(null, 1);
}

DLNA_Browser.prototype._registerCallbacks = function() {
Expand Down
5 changes: 5 additions & 0 deletions modules.js/AssFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ Ass.esc = function(str, escape)
return str.replace(/\\/g, '\\\u2060').replace(/\{/g, '\\{');
};

Ass.bold = function(bold, output)
{
return output === false ? '' : '{\\b'+(bold === false ? '0' : '1')+'}';
};

Ass.size = function(fontSize, output)
{
return output === false ? '' : '{\\fs'+fontSize+'}';
Expand Down
21 changes: 15 additions & 6 deletions modules.js/SelectionMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,17 @@ SelectionMenu.prototype.renderMenu = function(selectionPrefix, renderMode)
var opt;
for (var i = startIdx; i <= endIdx; ++i) {
opt = this.options[i];
if (i === this.selectionIdx)
// NOTE: Prefix stays on screen until cursor-move or re-render.z
finalString += Ass.yellow(c)+'> '+(typeof selectionPrefix === 'string' ?
Ass.esc(selectionPrefix, c)+' ' : '');

if (i === this.selectionIdx) finalString += '\n'+Ass.bold(true);

if (opt.isPlaying) finalString += Ass.green(c);
else if (i === this.selectionIdx) finalString += Ass.yellow(c);

// NOTE: Prefix stays on screen until cursor-move or re-render.z
finalString += i === this.selectionIdx ? '> ' : '| ';

finalString += typeof selectionPrefix === 'string' ?
Ass.esc(selectionPrefix, c)+' ' : '';

// If the menu option has no children to move to
// then it should be colored red and ignored
Expand All @@ -474,10 +481,12 @@ SelectionMenu.prototype.renderMenu = function(selectionPrefix, renderMode)
if (opt.isPlaying)
finalString += " <==";

if (i === this.selectionIdx || (opt.children != null && opt.children.length == 0))
if (i === this.selectionIdx) finalString += Ass.bold(false);

if (opt.isPlaying || i === this.selectionIdx || (opt.children != null && opt.children.length == 0))
finalString += Ass.white(c);
if (i !== endIdx)
finalString += '\n';
finalString += i === this.selectionIdx ? '\n\n' : '\n';
}
}

Expand Down