Skip to content
Snippets Groups Projects
Commit b8e2bbc1 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Allow direct border style numeric entry, max_length option

parent bbf3b573
Branches
No related tags found
No related merge requests found
// Post a meme // Post a meme
// @format.tab-size 4, @format.use-tabs true // @format.tab-size 4, @format.use-tabs true
// Supported options (e.g. in ctrl/modopts/postmeme.ini):
// color (default: 0)
// border (default: 0)
// random (default: false)
// max_length (default: 500)
"use strict"; "use strict";
require("key_defs.js", "KEY_LEFT"); require("key_defs.js", "KEY_LEFT");
require("sbbsdefs.js", "K_LINEWRAP"); require("sbbsdefs.js", "K_LINEWRAP");
...@@ -9,12 +15,13 @@ var options = load({}, "modopts.js", "postmeme"); ...@@ -9,12 +15,13 @@ var options = load({}, "modopts.js", "postmeme");
if (!options) options = {}; if (!options) options = {};
var lib = load({}, "meme_lib.js"); var lib = load({}, "meme_lib.js");
var maxMsgLen = 500;
function choose(border) function choose(border)
{ {
console.mnemonics(format("Style: ~Color, ~@Next@, ~@Previous@, or ~@Quit@ [%u]: ", border % lib.BORDER_COUNT)); console.mnemonics(format("Style: ~Color, ~@Next@, ~@Previous@, or ~@Quit@ [%u]: ", (border % lib.BORDER_COUNT) + 1));
switch(console.getkeys("C" + KEY_LEFT + KEY_RIGHT + "\r" + console.next_key + console.prev_key + console.quit_key)) { var ch = console.getkeys("C" + KEY_LEFT + KEY_RIGHT + "\r" + console.next_key + console.prev_key + console.quit_key, lib.BORDER_COUNT);
if (typeof ch == "number")
return ch - 1;
switch (ch) {
case console.quit_key: case console.quit_key:
return false; return false;
case '\r': case '\r':
...@@ -24,14 +31,14 @@ function choose(border) ...@@ -24,14 +31,14 @@ function choose(border)
case KEY_UP: case KEY_UP:
case KEY_LEFT: case KEY_LEFT:
case console.prev_key: case console.prev_key:
return -1; return console.prev_key;
default: default:
return 1; return console.next_key;
} }
} }
console.print("\x01N\x01Y\x01HWhat do you want to say?\x01N\r\n"); console.print("\x01N\x01Y\x01HWhat do you want to say?\x01N\r\n");
var text = console.getstr(maxMsgLen, K_LINEWRAP); var text = console.getstr(options.max_length || 500, K_LINEWRAP);
if (!text) if (!text)
exit(0); exit(0);
var attr = [ var attr = [
...@@ -59,15 +66,16 @@ while (!js.terminated) { ...@@ -59,15 +66,16 @@ while (!js.terminated) {
exit(1); exit(1);
if (ch === true) if (ch === true)
break; break;
if (ch === 'C') { if (typeof ch == "number")
border = ch;
else if (ch === 'C')
++color; ++color;
} else { else if (ch == console.next_key && border < lib.BORDER_COUNT - 1)
border += ch; ++border;
if (border < 0) { else if (ch == console.prev_key && border > 0)
--border;
else
console.beep(); console.beep();
border = 0;
}
}
} }
if (!msg) if (!msg)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment