Skip to content

Commit

Permalink
Sync up
Browse files Browse the repository at this point in the history
  • Loading branch information
NuSkooler committed Feb 20, 2023
2 parents 036a3dc + 8668eed commit 30cb21f
Show file tree
Hide file tree
Showing 13 changed files with 382 additions and 47 deletions.
Binary file modified art/themes/luciano_blocktronics/MMENU.ANS
Binary file not shown.
Binary file not shown.
Binary file modified art/themes/luciano_blocktronics/activitypub_social_manager.ans
Binary file not shown.
3 changes: 3 additions & 0 deletions art/themes/luciano_blocktronics/theme.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,9 @@
width: 35
itemFormat: "|00|03{subject}|00 {statusIndicator}"
focusItemFormat: "|00|19|15{subject!styleUpper}|00 {statusIndicator}"
itemFormat: "|00{statusIndicator} |00|03{subject}"
focusItemFormat: "|00{statusIndicator} |00|19|15{subject}"
textOverflow: "..."
}
MT2: {
height: 15
Expand Down
3 changes: 3 additions & 0 deletions core/activitypub/actor_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ exports.getModule = class ActivityPubActorSearch extends MenuModule {
async.series(
[
callback => {
if (this.viewControllers.view) {
this.viewControllers.view.setFocus(false);
}
return this.displayArtAndPrepViewController(
'main',
FormIds.main,
Expand Down
95 changes: 73 additions & 22 deletions core/full_menu_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function FullMenuView(options) {
}

for (let i = 0; i < this.dimens.height; i++) {
const text = `${strUtil.pad(this.fillChar, width, this.fillChar, 'left')}`;
const text = strUtil.pad('', width, this.fillChar);
this.client.term.write(
`${ansi.goto(
this.position.row + i,
Expand All @@ -77,6 +77,7 @@ function FullMenuView(options) {
this.autoAdjustHeightIfEnabled();

this.pages = []; // reset
this.currentPage = 0; // reset currentPage when pages reset

// Calculate number of items visible per column
this.itemsPerRow = Math.floor(this.dimens.height / (this.itemSpacing + 1));
Expand Down Expand Up @@ -240,14 +241,25 @@ function FullMenuView(options) {
sgr = index === this.focusedItemIndex ? this.getFocusSGR() : this.getSGR();
}

let renderLength = strUtil.renderStringLength(text);
if (this.hasTextOverflow() && item.col + renderLength > this.dimens.width) {
text =
strUtil.renderSubstr(
text,
0,
this.dimens.width - (item.col + this.textOverflow.length)
) + this.textOverflow;
const renderLength = strUtil.renderStringLength(text);

let relativeColumn = item.col - this.position.col;
if (relativeColumn < 0) {
relativeColumn = 0;
this.client.log.warn(
{ itemCol: item.col, positionColumn: this.position.col },
'Invalid item column detected in full menu'
);
}

if (relativeColumn + renderLength > this.dimens.width) {
if (this.hasTextOverflow()) {
text = strUtil.renderTruncate(text, {
length:
this.dimens.width - (relativeColumn + this.textOverflow.length),
omission: this.textOverflow,
});
}
}

let padLength = Math.min(item.fixedLength + 1, this.dimens.width);
Expand All @@ -270,14 +282,29 @@ FullMenuView.prototype.redraw = function () {

this.cachePositions();

// In case we get in a bad state, try to recover
if (this.currentPage < 0) {
this.currentPage = 0;
}

if (this.items.length) {
for (
let i = this.pages[this.currentPage].start;
i <= this.pages[this.currentPage].end;
++i
if (
this.currentPage > this.pages.length ||
!_.isObject(this.pages[this.currentPage])
) {
this.items[i].focused = this.focusedItemIndex === i;
this.drawItem(i);
this.client.log.warn(
{ currentPage: this.currentPage, pagesLength: this.pages.length },
'Invalid state! in full menu redraw'
);
} else {
for (
let i = this.pages[this.currentPage].start;
i <= this.pages[this.currentPage].end;
++i
) {
this.items[i].focused = this.focusedItemIndex === i;
this.drawItem(i);
}
}
}
};
Expand Down Expand Up @@ -358,6 +385,10 @@ FullMenuView.prototype.setItems = function (items) {
this.oldDimens = Object.assign({}, this.dimens);
}

// Reset the page on new items
this.currentPage = 0;
this.focusedItemIndex = 0;

FullMenuView.super_.prototype.setItems.call(this, items);

this.positionCacheExpired = true;
Expand All @@ -378,10 +409,20 @@ FullMenuView.prototype.focusNext = function () {
this.focusedItemIndex = 0;
this.currentPage = 0;
} else {
this.focusedItemIndex++;
if (this.focusedItemIndex > this.pages[this.currentPage].end) {
this.clearPage();
this.currentPage++;
if (
this.currentPage > this.pages.length ||
!_.isObject(this.pages[this.currentPage])
) {
this.client.log.warn(
{ currentPage: this.currentPage, pagesLength: this.pages.length },
'Invalid state in focusNext for full menu view'
);
} else {
this.focusedItemIndex++;
if (this.focusedItemIndex > this.pages[this.currentPage].end) {
this.clearPage();
this.currentPage++;
}
}
}

Expand All @@ -397,9 +438,19 @@ FullMenuView.prototype.focusPrevious = function () {
this.currentPage = this.pages.length - 1;
} else {
this.focusedItemIndex--;
if (this.focusedItemIndex < this.pages[this.currentPage].start) {
this.clearPage();
this.currentPage--;
if (
this.currentPage > this.pages.length ||
!_.isObject(this.pages[this.currentPage])
) {
this.client.log.warn(
{ currentPage: this.currentPage, pagesLength: this.pages.length },
'Bad focus state, ignoring call to focusPrevious.'
);
} else {
if (this.focusedItemIndex < this.pages[this.currentPage].start) {
this.clearPage();
this.currentPage--;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions core/oputil/oputil_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ function buildNewConfig() {
'new_user.in.hjson',
'doors.in.hjson',
'file_base.in.hjson',
'activitypub.in.hjson',
];

let includeFiles = [];
Expand Down
12 changes: 6 additions & 6 deletions core/string_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,29 +145,29 @@ function pad(s, len, padChar, justify, stringSGR, padSGR, useRenderLen = true) {
padSGR = padSGR || '';

const renderLen = useRenderLen ? renderStringLength(s) : s.length;
const padlen = len >= renderLen ? len - renderLen : 0;
const padLen = len > renderLen ? len - renderLen : 0;

switch (justify) {
case 'L':
case 'left':
s = `${stringSGR}${s}${padSGR}${Array(padlen).join(padChar)}`;
s = `${stringSGR}${s}${padSGR}${padChar.repeat(padLen)}`;
break;

case 'C':
case 'center':
case 'both':
{
const right = Math.ceil(padlen / 2);
const left = padlen - right;
const right = Math.ceil(padLen / 2);
const left = padLen - right;
s = `${padSGR}${Array(left + 1).join(
padChar
)}${stringSGR}${s}${padSGR}${Array(right + 1).join(padChar)}`;
)}${stringSGR}${s}${padSGR}${padChar.repeat(right)}`;
}
break;

case 'R':
case 'right':
s = `${padSGR}${Array(padlen).join(padChar)}${stringSGR}${s}`;
s = `${padSGR}${padChar.repeat(padLen)}${stringSGR}${s}`;
break;

default:
Expand Down
29 changes: 18 additions & 11 deletions core/vertical_menu_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ function VerticalMenuView(options) {
sgr = index === self.focusedItemIndex ? self.getFocusSGR() : self.getSGR();
}

text = strUtil.renderTruncate(text, {
length: this.dimens.width,
omission: this.truncateOmission,
});
if (this.hasTextOverflow()) {
text = strUtil.renderTruncate(text, {
length: this.dimens.width,
omission: this.textOverflow,
});
}

text = `${sgr}${strUtil.pad(
`${text}${this.styleSGR1}`,
Expand Down Expand Up @@ -143,18 +145,16 @@ VerticalMenuView.prototype.redraw = function () {
// erase old items
// :TODO: optimize this: only needed if a item is removed or new max width < old.
if (this.oldDimens) {
const blank = new Array(Math.max(this.oldDimens.width, this.dimens.width)).join(
' '
);
let seq = ansi.goto(this.position.row, this.position.col) + this.getSGR() + blank;
let row = this.position.row + 1;
const blank = ' '.repeat(Math.max(this.oldDimens.width, this.dimens.width));
let row = this.position.row;
const endRow = row + this.oldDimens.height - 2;

while (row <= endRow) {
seq += ansi.goto(row, this.position.col) + blank;
this.client.term.write(
ansi.goto(row, this.position.col) + this.getSGR() + blank
);
row += 1;
}
this.client.term.write(seq);
delete this.oldDimens;
}

Expand Down Expand Up @@ -247,6 +247,7 @@ VerticalMenuView.prototype.setItems = function (items) {
if (this.items && this.items.length) {
this.oldDimens = Object.assign({}, this.dimens);
}
this.focusedItemIndex = 0;

VerticalMenuView.super_.prototype.setItems.call(this, items);

Expand Down Expand Up @@ -406,6 +407,12 @@ VerticalMenuView.prototype.focusLast = function () {
return VerticalMenuView.super_.prototype.focusLast.call(this);
};

VerticalMenuView.prototype.setTextOverflow = function (overflow) {
VerticalMenuView.super_.prototype.setTextOverflow.call(this, overflow);

this.positionCacheExpired = true;
};

VerticalMenuView.prototype.setFocusItems = function (items) {
VerticalMenuView.super_.prototype.setFocusItems.call(this, items);

Expand Down
7 changes: 0 additions & 7 deletions core/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ function View(options) {
this.textStyle = options.textStyle || 'normal';
this.focusTextStyle = options.focusTextStyle || this.textStyle;
this.offsetsApplied = false;
this.truncateOmission = options.truncateOmission || '';

if (options.id) {
this.setId(options.id);
Expand Down Expand Up @@ -274,12 +273,6 @@ View.prototype.setPropertyValue = function (propName, value) {
this.validate = value;
}
break;

case 'truncateOmission':
if (_.isString(value)) {
this.truncateOmission = value;
}
break;
}

if (/styleSGR[0-9]{1,2}/.test(propName)) {
Expand Down
11 changes: 10 additions & 1 deletion docs/_docs/art/views/vertical_menu_view.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ Items can be selected on a menu via the cursor keys, Page Up, Page Down, Home, a
| `justify` | Sets the justification of each item in the list. Options: left (default), right, center |
| `itemFormat` | Sets the format for a list entry. See **Entry Formatting** in [MCI](../mci.md) |
| `fillChar` | Specifies a character to fill extra space in the menu with. Defaults to an empty space |
| `textOverflow` | If an entry cannot be displayed due to `width`, set overflow characters. See **Text Overflow** below |
| `items` | List of items to show in the menu. See **Items** below.
| `focusItemFormat` | Sets the format for a focused list entry. See **Entry Formatting** in [MCI](../mci.md) |
| `truncateOmission` | Sets the omission characters for truncated text if used. Defaults to an empty string. Commonly set to "..." |


### Hot Keys
Expand Down Expand Up @@ -70,6 +70,15 @@ If the list is for display only (there is no form action associated with it) you
["First item", "Second item", "Third Item"]
```

### Text Overflow

The `textOverflow` option is used to specify what happens when a text string is too long to fit in the `width` defined. If an entry is too long to display in the width specified

> :information_source: If `textOverflow` is not specified at all, a menu can become wider than the `width` if needed to display a single column.
> :information_source: Setting `textOverflow` to an empty string `textOverflow: ""` will cause the item to be truncated if necessary without any characters displayed
> :information_source: Otherwise, setting `textOverflow` to one or more characters will truncate the value if necessary and display those characters at the end. i.e. `textOverflow: ...`
## Example

Expand Down
Loading

0 comments on commit 30cb21f

Please sign in to comment.