webterm: fix bell icon in tabs

Presumably due to how js non-objects work in closures, the selected prop
we were reading out whenever a blit came in was stale.

Also, it was possible that a bell was hiding inside a %mor blit, so we
add a small helper for checking properly.
This commit is contained in:
fang 2022-03-25 15:38:56 +01:00
parent 8da6c20f70
commit 60ed368bc4
No known key found for this signature in database
GPG Key ID: EB035760C1BBA972
2 changed files with 13 additions and 2 deletions

View File

@ -12,7 +12,7 @@ import useTermState from './state';
import React from 'react';
import { Box, Col } from '@tlon/indigo-react';
import { makeTheme } from './lib/theme';
import { showBlit, csi } from './lib/blit';
import { showBlit, csi, hasBell } from './lib/blit';
import { DEFAULT_SESSION } from './constants';
import { retry } from './lib/retry';
@ -180,7 +180,8 @@ export default function Buffer({ name, selected, dark }: BufferProps) {
app: 'herm', path: '/session/' + name + '/view',
event: (e) => {
showBlit(ses.term, e);
if (e.bel && !selected) {
//NOTE getting selected from state because selected prop is stale
if (hasBell(e) && (useTermState.getState().selected !== name)) {
useTermState.getState().set((state) => {
state.sessions[name].hasBell = true;
});

View File

@ -73,3 +73,13 @@ export const showSlog = (term: Terminal, slog: string) => {
+ csi('r')
+ csi('u'));
};
export const hasBell = (blit: Blit) => {
if ('bel' in blit) {
return true;
} else if ('mor' in blit) {
return blit.mor.some(hasBell);
} else {
return false;
}
}