Onelinerz updates:

* Uses standard `itemFormat`
* Uses format of {userName} vs {username} (case)
* Has preview implemented as %TL2
This commit is contained in:
Bryan Ashby 2018-07-09 20:27:09 -06:00
parent 2f22d91bcf
commit 5c826abd5b
4 changed files with 77 additions and 93 deletions

View File

@ -43,6 +43,7 @@ Report your issue on Xibalba BBS, hop in #enigma-bbs on Freenet and chat, or
* Possible breaking changes in FSE: The MCI code `%TL13` for error indicator is now `%TL4`. This is part of a cleanup and standardization on "custom ranges". You may need to update your `theme.hjson` and related artwork. * Possible breaking changes in FSE: The MCI code `%TL13` for error indicator is now `%TL4`. This is part of a cleanup and standardization on "custom ranges". You may need to update your `theme.hjson` and related artwork.
* Removed view width auto-size: Some views still can auto-size their height, but in general you should be explicit in your themes * Removed view width auto-size: Some views still can auto-size their height, but in general you should be explicit in your themes
* More standardization using "custom ranges" and `itemFormat` / `focusItemFormat` semantics. Update your themes! * More standardization using "custom ranges" and `itemFormat` / `focusItemFormat` semantics. Update your themes!
* In addition to using `itemFormat`, the `onelinerz` module uses `userName` vs `username` (note the case) to match other modules
# 0.0.7-alpha to 0.0.8-alpha # 0.0.7-alpha to 0.0.8-alpha

View File

@ -88,11 +88,15 @@
fullLoginSequenceOnelinerz: { fullLoginSequenceOnelinerz: {
config: { config: {
listFormat: "|00|11{username:<12}|08: |03{oneliner:<59.59}" tsFormat: ddd h:mma
} }
0: { 0: {
mci: { mci: {
VM1: { height: 10, width: 20 } VM1: {
height: 10
width: 20
itemFormat: "|00|11{userName:<12}|08: |03{oneliner:<59.59}"
}
TM2: { TM2: {
focusTextStyle: first lower focusTextStyle: first lower
} }
@ -183,13 +187,15 @@
} }
mainMenuOnelinerz: { mainMenuOnelinerz: {
// :TODO: Need way to just duplicate entry here & in menu.hjson, e.g. use: someName + must supply next/etc. in menu
config: { config: {
listFormat: "|00|11{username:<12}|08: |03{oneliner:<59.59}" tsFormat: ddd h:mma
} }
0: { 0: {
mci: { mci: {
VM1: { height: 10, width: 10 } VM1: {
height: 10
itemFormat: "|00|11{userName:<12}|08: |03{oneliner:<59.59}"
}
TM2: { TM2: {
focusTextStyle: first lower focusTextStyle: first lower
} }

View File

@ -319,7 +319,8 @@ exports.MenuModule = class MenuModule extends PluginModule {
} }
prepViewController(name, formId, mciMap, cb) { prepViewController(name, formId, mciMap, cb) {
if(_.isUndefined(this.viewControllers[name])) { const needsCreated = _.isUndefined(this.viewControllers[name]);
if(needsCreated) {
const vcOpts = { const vcOpts = {
client : this.client, client : this.client,
formId : formId, formId : formId,
@ -334,13 +335,13 @@ exports.MenuModule = class MenuModule extends PluginModule {
}; };
return vc.loadFromMenuConfig(loadOpts, err => { return vc.loadFromMenuConfig(loadOpts, err => {
return cb(err, vc); return cb(err, vc, true);
}); });
} }
this.viewControllers[name].setFocus(true); this.viewControllers[name].setFocus(true);
return cb(null, this.viewControllers[name]); return cb(null, this.viewControllers[name], false);
} }
prepViewControllerWithArt(name, formId, options, cb) { prepViewControllerWithArt(name, formId, options, cb) {

View File

@ -9,11 +9,6 @@ const {
getTransactionDatabase getTransactionDatabase
} = require('./database.js'); } = require('./database.js');
const ViewController = require('./view_controller.js').ViewController;
const theme = require('./theme.js');
const ansi = require('./ansi_term.js');
const stringFormat = require('./string_format.js');
// deps // deps
const sqlite3 = require('sqlite3'); const sqlite3 = require('sqlite3');
const async = require('async'); const async = require('async');
@ -22,13 +17,9 @@ const moment = require('moment');
/* /*
Module :TODO: Module :TODO:
* Add pipe code support
- override max length & monitor *display* len as user types in order to allow for actual display len with color
* Add preview control: Shows preview with pipe codes resolved
* Add ability to at least alternate formatStrings -- every other * Add ability to at least alternate formatStrings -- every other
*/ */
exports.moduleInfo = { exports.moduleInfo = {
name : 'Onelinerz', name : 'Onelinerz',
desc : 'Standard local onelinerz', desc : 'Standard local onelinerz',
@ -37,20 +28,20 @@ exports.moduleInfo = {
}; };
const MciViewIds = { const MciViewIds = {
ViewForm : { view : {
Entries : 1, entries : 1,
AddPrompt : 2, addPrompt : 2,
}, },
AddForm : { add : {
NewEntry : 1, newEntry : 1,
EntryPreview : 2, entryPreview : 2,
AddPrompt : 3, addPrompt : 3,
} }
}; };
const FormIds = { const FormIds = {
View : 0, view : 0,
Add : 1, add : 1,
}; };
exports.getModule = class OnelinerzModule extends MenuModule { exports.getModule = class OnelinerzModule extends MenuModule {
@ -115,46 +106,29 @@ exports.getModule = class OnelinerzModule extends MenuModule {
async.waterfall( async.waterfall(
[ [
function clearAndDisplayArt(callback) { function prepArtAndViewController(callback) {
if(self.viewControllers.add) { if(self.viewControllers.add) {
self.viewControllers.add.setFocus(false); self.viewControllers.add.setFocus(false);
} }
if(clearScreen) { return self.prepViewControllerWithArt(
self.client.term.rawWrite(ansi.resetScreen()); 'view',
} FormIds.view,
{
theme.displayThemedAsset( clearScreen,
self.menuConfig.config.art.entries, trailingLF : false
self.client, },
{ font : self.menuConfig.font, trailingLF : false }, (err, artInfo, wasCreated) => {
(err, artData) => { if(!wasCreated) {
return callback(err, artData); self.viewControllers.view.setFocus(true);
self.viewControllers.view.getView(MciViewIds.view.addPrompt).redraw();
}
return callback(err);
} }
); );
}, },
function initOrRedrawViewController(artData, callback) {
if(_.isUndefined(self.viewControllers.add)) {
const vc = self.addViewController(
'view',
new ViewController( { client : self.client, formId : FormIds.View } )
);
const loadOpts = {
callingMenu : self,
mciMap : artData.mciMap,
formId : FormIds.View,
};
return vc.loadFromMenuConfig(loadOpts, callback);
} else {
self.viewControllers.view.setFocus(true);
self.viewControllers.view.getView(MciViewIds.ViewForm.AddPrompt).redraw();
return callback(null);
}
},
function fetchEntries(callback) { function fetchEntries(callback) {
const entriesView = self.viewControllers.view.getView(MciViewIds.ViewForm.Entries); const entriesView = self.viewControllers.view.getView(MciViewIds.view.entries);
const limit = entriesView.dimens.height; const limit = entriesView.dimens.height;
let entries = []; let entries = [];
@ -179,24 +153,22 @@ exports.getModule = class OnelinerzModule extends MenuModule {
); );
}, },
function populateEntries(entriesView, entries, callback) { function populateEntries(entriesView, entries, callback) {
const listFormat = self.menuConfig.config.listFormat || '{username}@{ts}: {oneliner}';// :TODO: should be userName to be consistent const tsFormat = self.menuConfig.config.timestampFormat || self.client.currentTheme.helpers.getDateFormat('short');
const tsFormat = self.menuConfig.config.timestampFormat || 'ddd h:mma';
entriesView.setItems(entries.map( e => { entriesView.setItems(entries.map( e => {
return stringFormat(listFormat, { return {
userId : e.user_id, userId : e.user_id,
username : e.user_name, userName : e.user_name,
oneliner : e.oneliner, oneliner : e.oneliner,
ts : e.timestamp.format(tsFormat), ts : e.timestamp.format(tsFormat),
} ); };
})); }));
entriesView.redraw(); entriesView.redraw();
return callback(null); return callback(null);
}, },
function finalPrep(callback) { function finalPrep(callback) {
const promptView = self.viewControllers.view.getView(MciViewIds.ViewForm.AddPrompt); const promptView = self.viewControllers.view.getView(MciViewIds.view.addPrompt);
promptView.setFocusItemIndex(1); // default to NO promptView.setFocusItemIndex(1); // default to NO
return callback(null); return callback(null);
} }
@ -216,37 +188,41 @@ exports.getModule = class OnelinerzModule extends MenuModule {
[ [
function clearAndDisplayArt(callback) { function clearAndDisplayArt(callback) {
self.viewControllers.view.setFocus(false); self.viewControllers.view.setFocus(false);
self.client.term.rawWrite(ansi.resetScreen());
theme.displayThemedAsset( return self.prepViewControllerWithArt(
self.menuConfig.config.art.add, 'add',
self.client, FormIds.add,
{ font : self.menuConfig.font }, {
(err, artData) => { clearScreen : true,
return callback(err, artData); trailingLF : false
},
(err, artInfo, wasCreated) => {
if(!wasCreated) {
self.viewControllers.add.setFocus(true);
self.viewControllers.add.redrawAll();
self.viewControllers.add.switchFocus(MciViewIds.add.newEntry);
}
return callback(err);
} }
); );
}, },
function initOrRedrawViewController(artData, callback) { function initPreviewUpdates(callback) {
if(_.isUndefined(self.viewControllers.add)) { const previewView = self.viewControllers.add.getView(MciViewIds.add.entryPreview);
const vc = self.addViewController( const entryView = self.viewControllers.add.getView(MciViewIds.add.newEntry);
'add', if(previewView) {
new ViewController( { client : self.client, formId : FormIds.Add } ) let timerId;
); entryView.on('key press', () => {
clearTimeout(timerId);
const loadOpts = { timerId = setTimeout( () => {
callingMenu : self, const focused = self.viewControllers.add.getFocusedView();
mciMap : artData.mciMap, if(focused === entryView) {
formId : FormIds.Add, previewView.setText(entryView.getData());
}; focused.setFocus(true);
}
return vc.loadFromMenuConfig(loadOpts, callback); }, 500);
} else { });
self.viewControllers.add.setFocus(true);
self.viewControllers.add.redrawAll();
self.viewControllers.add.switchFocus(MciViewIds.AddForm.NewEntry);
return callback(null);
} }
return callback(null);
} }
], ],
err => { err => {
@ -258,8 +234,8 @@ exports.getModule = class OnelinerzModule extends MenuModule {
} }
clearAddForm() { clearAddForm() {
this.setViewText('add', MciViewIds.AddForm.NewEntry, ''); this.setViewText('add', MciViewIds.add.newEntry, '');
this.setViewText('add', MciViewIds.AddForm.EntryPreview, ''); this.setViewText('add', MciViewIds.add.entryPreview, '');
} }
initDatabase(cb) { initDatabase(cb) {