Newer
Older
var centerText = (typeof(pCenter) == "boolean" ? pCenter : false);
var textColor = (typeof(pTextColor) == "string" ? pTextColor : "\1n\1w");
var lineColor = (typeof(pLineColor) == "string" ? pLineColor : "\1n\1k\1h");
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
// Output the text and a solid line on the next line.
if (centerText)
{
console.center(textColor + pText);
var solidLine = "";
var textLength = console.strlen(pText);
for (var i = 0; i < textLength; ++i)
solidLine += "Ä";
console.center(lineColor + solidLine);
}
else
{
console.print(textColor + pText);
console.crlf();
console.print(lineColor);
var textLength = console.strlen(pText);
for (var i = 0; i < textLength; ++i)
console.print("Ä");
console.crlf();
}
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
13407
13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
13421
13422
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496
}
// Returns whether the Synchronet compile date is at least May 12, 2013. That
// was when Digital Man's change to make bbs.msg_number work when a script is
// running first went into the Synchronet daily builds.
function compileDateAtLeast2013_05_12()
{
// system.compiled_when is in the following format:
// May 12 2013 05:02
var compileDateParts = system.compiled_when.split(" ");
if (compileDateParts.length < 4)
return false;
// Convert the month to a 1-based number
var compileMonth = 0;
if (/^Jan/.test(compileDateParts[0]))
compileMonth = 1;
else if (/^Feb/.test(compileDateParts[0]))
compileMonth = 2;
else if (/^Mar/.test(compileDateParts[0]))
compileMonth = 3;
else if (/^Apr/.test(compileDateParts[0]))
compileMonth = 4;
else if (/^May/.test(compileDateParts[0]))
compileMonth = 5;
else if (/^Jun/.test(compileDateParts[0]))
compileMonth = 6;
else if (/^Jul/.test(compileDateParts[0]))
compileMonth = 7;
else if (/^Aug/.test(compileDateParts[0]))
compileMonth = 8;
else if (/^Sep/.test(compileDateParts[0]))
compileMonth = 9;
else if (/^Oct/.test(compileDateParts[0]))
compileMonth = 10;
else if (/^Nov/.test(compileDateParts[0]))
compileMonth = 11;
else if (/^Dec/.test(compileDateParts[0]))
compileMonth = 12;
// Get the compileDay and compileYear as numeric variables
var compileDay = +compileDateParts[1];
var compileYear = +compileDateParts[2];
// Determine if the compile date is at least 2013-05-12
var compileDateIsAtLeastMin = true;
if (compileYear > 2013)
compileDateIsAtLeastMin = true;
else if (compileYear < 2013)
compileDateIsAtLeastMin = false;
else // compileYear is 2013
{
if (compileMonth > 5)
compileDateIsAtLeastMin = true
else if (compileMonth < 5)
compileDateIsAtLeastMin = false;
else // compileMonth is 5
compileDateIsAtLeastMin = (compileDay >= 12);
}
return compileDateIsAtLeastMin;
}
// Removes multiple, leading, and/or trailing spaces.
// The search & replace regular expressions used in this
// function came from the following URL:
// http://qodo.co.uk/blog/javascript-trim-leading-and-trailing-spaces
//
// Parameters:
// pString: The string to trim
// pLeading: Whether or not to trim leading spaces (optional, defaults to true)
// pMultiple: Whether or not to trim multiple spaces (optional, defaults to true)
// pTrailing: Whether or not to trim trailing spaces (optional, defaults to true)
function trimSpaces(pString, pLeading, pMultiple, pTrailing)
{
var leading = true;
var multiple = true;
var trailing = true;
if(typeof(pLeading) != "undefined")
leading = pLeading;
if(typeof(pMultiple) != "undefined")
multiple = pMultiple;
if(typeof(pTrailing) != "undefined")
trailing = pTrailing;
// To remove both leading & trailing spaces:
//pString = pString.replace(/(^\s*)|(\s*$)/gi,"");
if (leading)
pString = pString.replace(/(^\s*)/gi,"");
if (multiple)
pString = pString.replace(/[ ]{2,}/gi," ");
if (trailing)
pString = pString.replace(/(\s*$)/gi,"");
return pString;
}
// Calculates & returns a page number.
//
// Parameters:
// pTopIndex: The index (0-based) of the topmost item on the page
// pNumPerPage: The number of items per page
//
// Return value: The page number
function calcPageNum(pTopIndex, pNumPerPage)
{
return ((pTopIndex / pNumPerPage) + 1);
}
// Returns the greatest number of messages of all sub-boards within
// a message group.
//
// Parameters:
// pGrpIndex: The index of the message group
//
// Returns: The greatest number of messages of all sub-boards within
// the message group
function getGreatestNumMsgs(pGrpIndex)
{
// Sanity checking
if (typeof(pGrpIndex) != "number")
return 0;
if (typeof(msg_area.grp_list[pGrpIndex]) == "undefined")
return 0;
var greatestNumMsgs = 0;
var msgBase = null;
for (var subIndex = 0; subIndex < msg_area.grp_list[pGrpIndex].sub_list.length; ++subIndex)
{
msgBase = new MsgBase(msg_area.grp_list[pGrpIndex].sub_list[subIndex].code);
if (msgBase == null) continue;
if (msgBase.open())
{
if (msgBase.total_msgs > greatestNumMsgs)
greatestNumMsgs = msgBase.total_msgs;
msgBase.close();
}
}
return greatestNumMsgs;
}
// Inputs a keypress from the user and handles some ESC-based
// characters such as PageUp, PageDown, and ESC. If PageUp
// or PageDown are pressed, this function will return the
// string "\1PgUp" (KEY_PAGE_UP) or "\1Pgdn" (KEY_PAGE_DOWN),
// respectively. Also, F1-F5 will be returned as "\1F1"
// through "\1F5", respectively.
// Thanks goes to Psi-Jack for the original impementation
// of this function.
//
// Parameters:
// pGetKeyMode: Optional - The mode bits for console.getkey().
// If not specified, K_NONE will be used.
//
// Return value: The user's keypress
function getKeyWithESCChars(pGetKeyMode)
{
var getKeyMode = K_NONE;
if (typeof(pGetKeyMode) == "number")
getKeyMode = pGetKeyMode;
var userInput = console.getkey(getKeyMode);
if (userInput == KEY_ESC) {
switch (console.inkey(K_NOECHO|K_NOSPIN, 2)) {
case '[':
switch (console.inkey(K_NOECHO|K_NOSPIN, 2)) {
case 'V':
userInput = KEY_PAGE_UP;
break;
case 'U':
userInput = KEY_PAGE_DOWN;
break;
}
break;
case 'O':
switch (console.inkey(K_NOECHO|K_NOSPIN, 2)) {
case 'P':
userInput = "\1F1";
break;
case 'Q':
userInput = "\1F2";
break;
case 'R':
userInput = "\1F3";
break;
case 'S':
userInput = "\1F4";
break;
case 't':
userInput = "\1F5";
break;
}
default:
break;
}
}
return userInput;
}
// Finds the next or previous non-empty message sub-board. Returns an
// object containing the message group & sub-board indexes. If all of
// the next/previous sub-boards are empty, then the given current indexes
// will be returned.
//
// Parameters:
// pStartGrpIdx: The index of the message group to start from
// pStartSubIdx: The index of the sub-board in the message group to start from
// pForward: Boolean - Whether or not to search forward (true) or backward (false).
// Optional; defaults to true, to search forward.
//
// Return value: An object with the following properties:
// foundSubBoard: Boolean - Whether or not a different sub-board was found
// grpIdx: The message group index of the found sub-board
// subIdx: The sub-board index in the group of the found sub-board
// subCode: The internal code of the sub-board
// subChanged: Boolean - Whether or not the found sub-board is
// different from the one that was passed in
// paramsValid: Boolean - Whether or not all the passed-in parameters
// were valid.
function findNextOrPrevNonEmptySubBoard(pStartGrpIdx, pStartSubIdx, pForward)
{
var retObj = new Object();
retObj.grpIdx = pStartGrpIdx;
retObj.subIdx = pStartSubIdx;
retObj.subCode = msg_area.grp_list[pStartGrpIdx].sub_list[pStartSubIdx].code;
retObj.foundSubBoard = false;
// Sanity checking
retObj.paramsValid = ((pStartGrpIdx >= 0) && (pStartGrpIdx < msg_area.grp_list.length) &&
(pStartSubIdx >= 0) &&
(pStartSubIdx < msg_area.grp_list[pStartGrpIdx].sub_list.length));
if (!retObj.paramsValid)
return retObj;
var grpIdx = pStartGrpIdx;
var subIdx = pStartSubIdx;
var searchForward = (typeof(pForward) == "boolean" ? pForward : true);
if (searchForward)
{
// Advance the sub-board (and group) index, and determine whether or not
// to do the search (i.e., we might not want to if the starting sub-board
// is the last sub-board in the last group).
var searchForSubBoard = true;
if (subIdx < msg_area.grp_list[grpIdx].sub_list.length - 1)
++subIdx;
else
{
if ((grpIdx < msg_area.grp_list.length - 1) && (msg_area.grp_list[grpIdx+1].sub_list.length > 0))
{
subIdx = 0;
++grpIdx;
}
else
searchForSubBoard = false;
}
// If we can search, then do it.
if (searchForSubBoard)
{
while (numMsgsInSubBoard(msg_area.grp_list[grpIdx].sub_list[subIdx].code) == 0)
{
if (subIdx < msg_area.grp_list[grpIdx].sub_list.length - 1)
++subIdx;
else
{
if ((grpIdx < msg_area.grp_list.length - 1) && (msg_area.grp_list[grpIdx+1].sub_list.length > 0))
{
subIdx = 0;
++grpIdx;
}
else
break; // Stop searching
}
}
}
}
else
{
// Search the sub-boards in reverse
// Decrement the sub-board (and group) index, and determine whether or not
// to do the search (i.e., we might not want to if the starting sub-board
// is the first sub-board in the first group).
var searchForSubBoard = true;
if (subIdx > 0)
--subIdx;
else
{
if ((grpIdx > 0) && (msg_area.grp_list[grpIdx-1].sub_list.length > 0))
{
--grpIdx;
subIdx = msg_area.grp_list[grpIdx].sub_list.length - 1;
}
else
searchForSubBoard = false;
}
// If we can search, then do it.
if (searchForSubBoard)
{
while (numMsgsInSubBoard(msg_area.grp_list[grpIdx].sub_list[subIdx].code) == 0)
{
if (subIdx > 0)
--subIdx;
else
{
if ((grpIdx > 0) && (msg_area.grp_list[grpIdx-1].sub_list.length > 0))
{
--grpIdx;
subIdx = msg_area.grp_list[grpIdx].sub_list.length - 1;
}
else
break; // Stop searching
}
}
}
}
// If we found a sub-board with messages in it, then set the variables
// in the return object
if (numMsgsInSubBoard(msg_area.grp_list[grpIdx].sub_list[subIdx].code) > 0)
{
retObj.grpIdx = grpIdx;
retObj.subIdx = subIdx;
retObj.subCode = msg_area.grp_list[grpIdx].sub_list[subIdx].code;
retObj.foundSubBoard = true;
retObj.subChanged = ((grpIdx != pStartGrpIdx) || (subIdx != pStartSubIdx));
}
return retObj;
}
// Returns the number of messages in a sub-board.
//
// Parameters:
// pSubBoardCode: The internal code of the sub-board to check
// pIncludeDeleted: Optional boolean - Whether or not to include deleted
// messages in the count. Defaults to false.
//
// Return value: The number of messages in the sub-board
function numMsgsInSubBoard(pSubBoardCode, pIncludeDeleted)
{
var numMessages = 0;
var msgbase = new MsgBase(pSubBoardCode);
if (msgbase.open())
{
var includeDeleted = (typeof(pIncludeDeleted) == "boolean" ? pIncludeDeleted : false);
if (includeDeleted)
numMessages = msgbase.total_msgs;
else
{
// Don't include deleted messages. Go through each message
// in the sub-board and count the ones that aren't marked
// as deleted.
for (var msgIdx = 0; msgIdx < msgbase.total_msgs; ++msgIdx)
{
var msgHdr = msgbase.get_msg_header(true, msgIdx, false);
if ((msgHdr != null) && ((msgHdr.attr & MSG_DELETE) == 0))
++numMessages;
}
}
msgbase.close();
}
return numMessages;
}
// Replaces @-codes in a string and returns the new string.
//
// Parameters:
// pStr: A string in which to replace @-codes
//
// Return value: A version of the string with @-codes interpreted
function replaceAtCodesInStr(pStr)
{
if (typeof(pStr) != "string")
return "";
// This code was originally written by Deuce. I updated it to check whether
// the string returned by bbs.atcode() is null, and if so, just return
// the original string.
return pStr.replace(/@([^@]+)@/g, function(m, code) {
var decoded = bbs.atcode(code);
return (decoded != null ? decoded : "@" + code + "@");
});
}
// Shortens a string, accounting for control/attribute codes. Returns a new
// (shortened) copy of the string.
//
// Parameters:
// pStr: The string to shorten
// pNewLength: The new (shorter) length of the string
//
// Return value: The shortened version of the string
function shortenStrWithAttrCodes(pStr, pNewLength)
{
if (typeof(pStr) != "string")
return "";
if (typeof(pNewLength) != "number")
return pStr;
if (pNewLength >= console.strlen(pStr))
return pStr;
var strCopy = "";
var tmpStr = "";
var strIdx = 0;
var lengthGood = true;
while (lengthGood && (strIdx < pStr.length))
{
tmpStr = strCopy + pStr.charAt(strIdx++);
if (console.strlen(tmpStr) <= pNewLength)
strCopy = tmpStr;
else
lengthGood = false;
}
return strCopy;
}
// Returns whether a given name matches the logged-in user's handle, alias, or
// name.
//
// Parameters:
// pName: A name to match against the logged-in user
//
// Return value: Boolean - Whether or not the given name matches the logged-in
// user's handle, alias, or name
function userHandleAliasNameMatch(pName)
{
if (typeof(pName) != "string")
return false;
var userMatch = false;
var nameUpper = pName.toUpperCase();
if (user.handle.length > 0)
userMatch = (nameUpper.indexOf(user.handle.toUpperCase()) > -1);
if (!userMatch && (user.alias.length > 0))
userMatch = (nameUpper.indexOf(user.alias.toUpperCase()) > -1);
if (!userMatch && (user.name.length > 0))
userMatch = (nameUpper.indexOf(user.name.toUpperCase()) > -1);
return userMatch;
}
// Displays a range of text lines on the screen and allows scrolling through them
// with the up & down arrow keys, PageUp, PageDown, HOME, and END. It is assumed
// that the array of text lines are already truncated to fit in the width of the
// text area, as a speed optimization.
//
// Parameters:
// pTxtLines: The array of text lines to allow scrolling for
// pTopLineIdx: The index of the text line to display at the top
// pTxtAttrib: The attribute(s) to apply to the text lines
// pWriteTxtLines: Boolean - Whether or not to write the text lines (in addition
// to doing the message loop). If false, this will only do the
// the message loop. This parameter is intended as a screen
// refresh optimization.
// pTopLeftX: The upper-left corner column for the text area
// pTopLeftY: The upper-left corner row for the text area
// pWidth: The width of the text area
// pHeight: The height of the text area
// pPostWriteCurX: The X location for the cursor after writing the message
// lines
// pPostWriteCurY: The Y location for the cursor after writing the message
// lines
// pScrollUpdateFn: A function that the caller can provide for updating the
// scroll position. This function has one parameter:
// - fractionToLastPage: The fraction of the top index divided
// by the top index for the last page (basically, the progress
// to the last page).
//
// Return value: An object with the following properties:
// lastKeypress: The last key pressed by the user (a string)
// topLineIdx: The new top line index of the text lines, in case of scrolling
function scrollTextLines(pTxtLines, pTopLineIdx, pTxtAttrib, pWriteTxtLines, pTopLeftX, pTopLeftY,
pWidth, pHeight, pPostWriteCurX, pPostWriteCurY, pScrollUpdateFn)
{
// Variables for the top line index for the last page, scrolling, etc.
var topLineIdxForLastPage = pTxtLines.length - pHeight;
if (topLineIdxForLastPage < 0)
topLineIdxForLastPage = 0;
var msgFractionShown = pHeight / pTxtLines.length;
if (msgFractionShown > 1)
msgFractionShown = 1.0;
var fractionToLastPage = 0;
var lastTxtRow = pTopLeftY + pHeight - 1;
var txtLineFormatStr = "%-" + pWidth + "s";
var retObj = new Object();
retObj.lastKeypress = "";
retObj.topLineIdx = pTopLineIdx;
13514
13515
13516
13517
13518
13519
13520
13521
13522
13523
13524
13525
13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
var writeTxtLines = pWriteTxtLines;
var continueOn = true;
while (continueOn)
{
// If we are to write the text lines, then write each of them and also
// clear out the rest of the row on the screen
if (writeTxtLines)
{
// If the scroll update function parameter is a function, then calculate
// the fraction to the last page and call the scroll update function.
if (typeof(pScrollUpdateFn) == "function")
{
if (topLineIdxForLastPage != 0)
fractionToLastPage = retObj.topLineIdx / topLineIdxForLastPage;
pScrollUpdateFn(fractionToLastPage);
}
var screenY = pTopLeftY;
for (var lineIdx = retObj.topLineIdx; (lineIdx < pTxtLines.length) && (screenY <= lastTxtRow); ++lineIdx)
{
console.gotoxy(pTopLeftX, screenY++);
// Print the text line, then clear the rest of the line
console.print(pTxtAttrib + pTxtLines[lineIdx]);
printf("\1n%" + +(pWidth - console.strlen(pTxtLines[lineIdx])) + "s", "");
}
// If there are still some lines left in the message reading area, then
// clear the lines.
console.print("\1n" + pTxtAttrib);
while (screenY <= lastTxtRow)
{
console.gotoxy(pTopLeftX, screenY++);
printf(txtLineFormatStr, "");
}
}
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
13646
13647
13648
13649
writeTxtLines = false;
// Get a keypress from the user and take action based on it
console.gotoxy(pPostWriteCurX, pPostWriteCurY);
retObj.lastKeypress = getKeyWithESCChars(K_UPPER|K_NOCRLF|K_NOECHO|K_NOSPIN);
switch (retObj.lastKeypress)
{
case KEY_UP:
if (retObj.topLineIdx > 0)
{
--retObj.topLineIdx;
writeTxtLines = true;
}
break;
case KEY_DOWN:
if (retObj.topLineIdx < topLineIdxForLastPage)
{
++retObj.topLineIdx;
writeTxtLines = true;
}
break;
case KEY_PAGE_DOWN: // Next page
if (retObj.topLineIdx < topLineIdxForLastPage)
{
retObj.topLineIdx += pHeight;
if (retObj.topLineIdx > topLineIdxForLastPage)
retObj.topLineIdx = topLineIdxForLastPage;
writeTxtLines = true;
}
break;
case KEY_PAGE_UP: // Previous page
if (retObj.topLineIdx > 0)
{
retObj.topLineIdx -= pHeight;
if (retObj.topLineIdx < 0)
retObj.topLineIdx = 0;
writeTxtLines = true;
}
break;
case KEY_HOME: // First page
if (retObj.topLineIdx > 0)
{
retObj.topLineIdx = 0;
writeTxtLines = true;
}
break;
case KEY_END: // Last page
if (retObj.topLineIdx < topLineIdxForLastPage)
{
retObj.topLineIdx = topLineIdxForLastPage;
writeTxtLines = true;
}
break;
default:
continueOn = false;
break;
}
}
return retObj;
}
// Displays a Frame on the screen and allows scrolling through it with the up &
// down arrow keys, PageUp, PageDown, HOME, and END.
//
// Parameters:
// pFrame: A Frame object to display & scroll through
// pScrollbar: A ScrollBar object associated with the Frame object
// pTopLineIdx: The index of the text line to display at the top
// pTxtAttrib: The attribute(s) to apply to the text lines
// pWriteTxtLines: Boolean - Whether or not to write the text lines (in addition
// to doing the message loop). If false, this will only do the
// the message loop. This parameter is intended as a screen
// refresh optimization.
// pPostWriteCurX: The X location for the cursor after writing the message
// lines
// pPostWriteCurY: The Y location for the cursor after writing the message
// lines
// pScrollUpdateFn: A function that the caller can provide for updating the
// scroll position. This function has one parameter:
// - fractionToLastPage: The fraction of the top index divided
// by the top index for the last page (basically, the progress
// to the last page).
//
// Return value: An object with the following properties:
// lastKeypress: The last key pressed by the user (a string)
// topLineIdx: The new top line index of the text lines, in case of scrolling
function scrollFrame(pFrame, pScrollbar, pTopLineIdx, pTxtAttrib, pWriteTxtLines, pPostWriteCurX,
pPostWriteCurY, pScrollUpdateFn)
{
// Variables for the top line index for the last page, scrolling, etc.
var topLineIdxForLastPage = pFrame.data_height - pFrame.height;
if (topLineIdxForLastPage < 0)
topLineIdxForLastPage = 0;
var retObj = new Object();
retObj.lastKeypress = "";
retObj.topLineIdx = pTopLineIdx;
if (pTopLineIdx > 0)
pFrame.scrollTo(0, pTopLineIdx);
var writeTxtLines = pWriteTxtLines;

nightfox
committed
if (writeTxtLines)
{
pFrame.invalidate(); // Force drawing on the next call to draw() or cycle()
pFrame.cycle();
//pFrame.draw();
}
var cycleFrame = true;
var continueOn = true;
while (continueOn)
{
// If we are to write the text lines, then draw the frame.
// TODO: Do we really need this? Will this be different from
// scrollTextLines()?
//if (writeTxtLines)
// pFrame.draw();
if (cycleFrame)
{
// Invalidate the frame to force it to redraw everything, as a
// workaround to clear the background before writing again
// TODO: I might want to remove this invalidate() later when
// Frame is fixed to redraw better on scrolling.
pFrame.invalidate();
// Cycle the scrollbar & frame to get them to scroll

nightfox
committed
if (pScrollbar != null)
pScrollbar.cycle();

nightfox
committed
pFrame.cycle();
13678
13679
13680
13681
13682
13683
13684
13685
13686
13687
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731
13732
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
}
writeTxtLines = false;
cycleFrame = false;
// Get a keypress from the user and take action based on it
console.gotoxy(pPostWriteCurX, pPostWriteCurY);
retObj.lastKeypress = getKeyWithESCChars(K_UPPER|K_NOCRLF|K_NOECHO|K_NOSPIN);
switch (retObj.lastKeypress)
{
case KEY_UP:
if (retObj.topLineIdx > 0)
{
pFrame.scroll(0, -1);
--retObj.topLineIdx;
cycleFrame = true;
writeTxtLines = true;
}
break;
case KEY_DOWN:
if (retObj.topLineIdx < topLineIdxForLastPage)
{
pFrame.scroll(0, 1);
cycleFrame = true;
++retObj.topLineIdx;
writeTxtLines = true;
}
break;
case KEY_PAGE_DOWN: // Next page
if (retObj.topLineIdx < topLineIdxForLastPage)
{
//pFrame.scroll(0, pFrame.height);
retObj.topLineIdx += pFrame.height;
if (retObj.topLineIdx > topLineIdxForLastPage)
retObj.topLineIdx = topLineIdxForLastPage;
pFrame.scrollTo(1, retObj.topLineIdx+1);
cycleFrame = true;
writeTxtLines = true;
}
break;
case KEY_PAGE_UP: // Previous page
if (retObj.topLineIdx > 0)
{
//pFrame.scroll(0, -(pFrame.height));
retObj.topLineIdx -= pFrame.height;
if (retObj.topLineIdx < 0)
retObj.topLineIdx = 0;
pFrame.scrollTo(1, retObj.topLineIdx+1);
cycleFrame = true;
writeTxtLines = true;
}
break;
case KEY_HOME: // First page
//pFrame.home();
pFrame.scrollTo(1, 1);
cycleFrame = true;
retObj.topLineIdx = 0;
break;
case KEY_END: // Last page
//pFrame.end();
pFrame.scrollTo(1, topLineIdxForLastPage+1);
cycleFrame = true;
retObj.topLineIdx = topLineIdxForLastPage;
break;
default:
continueOn = false;
break;
}
}
return retObj;
13749
13750
13751
13752
13753
13754
13755
13756
13757
13758
13759
13760
13761
13762
13763
13764
13765
13766
13767
13768
13769
13770
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
13786
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834
13835
13836
13837
13838
13839
13840
13841
13842
13843
13844
13845
13846
13847
13848
13849
13850
13851
13852
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864
13865
13866
13867
13868
13869
13870
13871
13872
13873
13874
13875
13876
13877
13878
13879
13880
13881
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
13895
13896
13897
13898
13899
13900
13901
13902
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13914
13915
13916
13917
13918
13919
13920
13921
13922
13923
13924
13925
13926
13927
13928
13929
13930
13931
13932
13933
13934
13935
13936
13937
13938
13939
13940
13941
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964
13965
13966
13967
13968
13969
13970
13971
13972
13973
13974
13975
13976
13977
13978
13979
13980
13981
13982
13983
13984
13985
13986
13987
}
// Finds the (1-based) page number of an item by number (1-based). If no page
// is found, then the return value will be 0.
//
// Parameters:
// pItemNum: The item number (1-based)
// pNumPerPage: The number of items per page
// pTotoalNum: The total number of items in the list
// pReverseOrder: Boolean - Whether or not the list is in reverse order. If not specified,
// this will default to false.
//
// Return value: The page number (1-based) of the item number. If no page is found,
// the return value will be 0.
function findPageNumOfItemNum(pItemNum, pNumPerPage, pTotalNum, pReverseOrder)
{
if ((typeof(pItemNum) != "number") || (typeof(pNumPerPage) != "number") || (typeof(pTotalNum) != "number"))
return 0;
if ((pItemNum < 1) || (pItemNum > pTotalNum))
return 0;
var reverseOrder = (typeof(pReverseOrder) == "boolean" ? pReverseOrder : false);
var itemPageNum = 0;
if (reverseOrder)
{
var pageNum = 1;
for (var topNum = pTotalNum; ((topNum > 0) && (itemPageNum == 0)); topNum -= pNumPerPage)
{
if ((pItemNum <= topNum) && (pItemNum >= topNum-pNumPerPage+1))
itemPageNum = pageNum;
++pageNum;
}
}
else // Forward order
itemPageNum = Math.ceil(pItemNum / pNumPerPage);
return itemPageNum;
}
// This function converts a search mode string to one of the defined search value
// constants. If the passed-in mode string is unknown, then the return value will
// be SEARCH_NONE (-1).
//
// Parameters:
// pSearchTypeStr: A string describing a search mode ("keyword_search", "from_name_search",
// "to_name_search", "to_user_search", "new_msg_scan", "new_msg_scan_cur_sub",
// "new_msg_scan_cur_grp", "new_msg_scan_all", "to_user_new_scan",
// "to_user_all_scan")
//
// Return value: An integer representing the search value (SEARCH_KEYWORD,
// SEARCH_FROM_NAME, SEARCH_TO_NAME_CUR_MSG_AREA,
// SEARCH_TO_USER_CUR_MSG_AREA), or SEARCH_NONE (-1) if the passed-in
// search type string is unknown.
function searchTypeStrToVal(pSearchTypeStr)
{
if (typeof(pSearchTypeStr) != "string")
return SEARCH_NONE;
var searchTypeInt = SEARCH_NONE;
var modeStr = pSearchTypeStr.toLowerCase();
if (modeStr == "keyword_search")
searchTypeInt = SEARCH_KEYWORD;
else if (modeStr == "from_name_search")
searchTypeInt = SEARCH_FROM_NAME;
else if (modeStr == "to_name_search")
searchTypeInt = SEARCH_TO_NAME_CUR_MSG_AREA;
else if (modeStr == "to_user_search")
searchTypeInt = SEARCH_TO_USER_CUR_MSG_AREA;
else if (modeStr == "new_msg_scan")
searchTypeInt = SEARCH_MSG_NEWSCAN;
else if (modeStr == "new_msg_scan_cur_sub")
searchTypeInt = SEARCH_MSG_NEWSCAN_CUR_SUB;
else if (modeStr == "new_msg_scan_cur_grp")
searchTypeInt = SEARCH_MSG_NEWSCAN_CUR_GRP;
else if (modeStr == "new_msg_scan_all")
searchTypeInt = SEARCH_MSG_NEWSCAN_ALL;
else if (modeStr == "to_user_new_scan")
searchTypeInt = SEARCH_TO_USER_NEW_SCAN;
else if (modeStr == "to_user_new_scan_cur_sub")
searchTypeInt = SEARCH_TO_USER_NEW_SCAN_CUR_SUB;
else if (modeStr == "to_user_new_scan_cur_grp")
searchTypeInt = SEARCH_TO_USER_NEW_SCAN_CUR_GRP;
else if (modeStr == "to_user_new_scan_all")
searchTypeInt = SEARCH_TO_USER_NEW_SCAN_ALL;
else if (modeStr == "to_user_all_scan")
searchTypeInt = SEARCH_ALL_TO_USER_SCAN;
return searchTypeInt;
}
// This function converts a search type value to a string description.
//
// Parameters:
// pSearchType: The search type value to convert
//
// Return value: A string describing the search type value
function searchTypeValToStr(pSearchType)
{
if (typeof(pSearchType) != "number")
return "Unknown (not a number)";
var searchTypeStr = "";
switch (pSearchType)
{
case SEARCH_NONE:
searchTypeStr = "None (SEARCH_NONE)";
break;
case SEARCH_KEYWORD:
searchTypeStr = "Keyword (SEARCH_KEYWORD)";
break;
case SEARCH_FROM_NAME:
searchTypeStr = "'From' name (SEARCH_FROM_NAME)";
break;
case SEARCH_TO_NAME_CUR_MSG_AREA:
searchTypeStr = "'To' name (SEARCH_TO_NAME_CUR_MSG_AREA)";
break;
case SEARCH_TO_USER_CUR_MSG_AREA:
searchTypeStr = "To you (SEARCH_TO_USER_CUR_MSG_AREA)";
break;
case SEARCH_MSG_NEWSCAN:
searchTypeStr = "New message scan (SEARCH_MSG_NEWSCAN)";
break;
case SEARCH_MSG_NEWSCAN_CUR_SUB:
searchTypeStr = "New in current message area (SEARCH_MSG_NEWSCAN_CUR_SUB)";
break;
case SEARCH_MSG_NEWSCAN_CUR_GRP:
searchTypeStr = "New in current message group (SEARCH_MSG_NEWSCAN_CUR_GRP)";
break;
case SEARCH_MSG_NEWSCAN_ALL:
searchTypeStr = "Newscan - All (SEARCH_MSG_NEWSCAN_ALL)";
break;
case SEARCH_TO_USER_NEW_SCAN:
searchTypeStr = "To You new scan (SEARCH_TO_USER_NEW_SCAN)";
break;
case SEARCH_TO_USER_NEW_SCAN_CUR_SUB:
searchTypeStr = "To You new scan, current sub-board (SEARCH_TO_USER_NEW_SCAN_CUR_SUB)";
break;
case SEARCH_TO_USER_NEW_SCAN_CUR_GRP:
searchTypeStr = "To You new scan, current group (SEARCH_TO_USER_NEW_SCAN_CUR_GRP)";
break;
case SEARCH_TO_USER_NEW_SCAN_ALL:
searchTypeStr = "To You new scan, all sub-boards (SEARCH_TO_USER_NEW_SCAN_ALL)";
break;
case SEARCH_ALL_TO_USER_SCAN:
searchTypeStr = "All To You scan (SEARCH_ALL_TO_USER_SCAN)";
break;
default:
searchTypeStr = "Unknown (" + pSearchType + ")";
break;
}
return searchTypeStr;
}
// This function converts a reader mode string to one of the defined reader mode
// value constants. If the passed-in mode string is unknown, then the return value
// will be -1.
//
// Parameters:
// pModeStr: A string describing a reader mode ("read", "reader", "list", "lister")
//
// Return value: An integer representing the reader mode value (READER_MODE_READ,
// READER_MODE_LIST), or -1 if the passed-in mode string is unknown.
function readerModeStrToVal(pModeStr)
{
if (typeof(pModeStr) != "string")
return -1;
var readerModeInt = -1;
var modeStr = pModeStr.toLowerCase();
if ((modeStr == "read") || (modeStr == "reader"))
readerModeInt = READER_MODE_READ;
else if ((modeStr == "list") || (modeStr == "lister"))
readerModeInt = READER_MODE_LIST;
return readerModeInt;
}
// This function returns a boolean to signify whether or not the user's
// terminal supports both high-ASCII characters and ANSI codes.
function canDoHighASCIIAndANSI()
{
//return (console.term_supports(USER_ANSI) && (user.settings & USER_NO_EXASCII == 0));
return (console.term_supports(USER_ANSI));
}
// Searches a given range in an open message base and returns an object with arrays
// containing the message headers (0-based indexed and indexed by message number)
// with the message headers of any found messages.
//
// Parameters:
// pSubCode: The internal code of the message sub-board
// pMsgbase: A message base object in which to search messages
// pSearchType: The type of search to do (one of the SEARCH_ values)
// pSearchString: The string to search for.
// pListingPersonalEmailFromUser: Optional boolean - Whether or not we're listing
// personal email sent by the user. This defaults
// to false.
// pStartIndex: The starting message index (0-based). Optional; defaults to 0.
// pEndIndex: One past the last message index. Optional; defaults to the total number
// of messages.
//
// Return value: An object with the following arrays:
// indexed: A 0-based indexed array of message headers
function searchMsgbase(pSubCode, pMsgbase, pSearchType, pSearchString,
pListingPersonalEmailFromUser, pStartIndex, pEndIndex)
{
var msgHeaders = new Object();
msgHeaders.indexed = new Array();
if ((pSubCode != "mail") && ((typeof(pSearchString) != "string") || !searchTypePopulatesSearchResults(pSearchType)))
return msgHeaders;
var startMsgIndex = 0;
var endMsgIndex = pMsgbase.total_msgs;
if (typeof(pStartIndex) == "number")
{
if ((pStartIndex >= 0) && (pStartIndex < pMsgbase.total_msgs))
startMsgIndex = pStartIndex;
}
if (typeof(pEndIndex) == "number")
{
if ((pEndIndex >= 0) && (pEndIndex > startMsgIndex) && (pEndIndex <= pMsgbase.total_msgs))
endMsgIndex = pEndIndex;
}
// Define a search function for the message field we're going to search
var readingPersonalEmailFromUser = (typeof(pListingPersonalEmailFromUser) == "boolean" ? pListingPersonalEmailFromUser : false);
var matchFn = null;
switch (pSearchType)
{
// It might seem odd to have SEARCH_NONE in here, but it's here because
// when reading personal email, we need to search for messages only to
// the current user.
case SEARCH_NONE:
if (pSubCode == "mail")
{
// Set up the match function slightly differently depending on whether
// we're looking for mail from the current user or to the current user.
if (readingPersonalEmailFromUser)
{
matchFn = function(pSearchStr, pMsgHdr, pMsgBase, pSubBoardCode) {
var msgText = strip_ctrl(pMsgBase.get_msg_body(true, pMsgHdr.offset));
return gAllPersonalEmailOptSpecified || msgIsFromUser(pMsgHdr);
}
}
else
{
matchFn = function(pSearchStr, pMsgHdr, pMsgBase, pSubBoardCode) {
var msgText = strip_ctrl(pMsgBase.get_msg_body(true, pMsgHdr.offset));
return gAllPersonalEmailOptSpecified || msgIsToUserByNum(pMsgHdr);