Strip ANSI escape sequences

References: https://todo.sr.ht/~emersion/gamja/11
This commit is contained in:
Simon Ser 2020-08-04 14:25:05 +02:00
parent b37dfb77fe
commit 96c890f1f5
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
3 changed files with 62 additions and 5 deletions

View file

@ -1,5 +1,6 @@
import { html, Component } from "/lib/index.js";
import linkify from "/lib/linkify.js";
import { strip as stripANSI } from "/lib/ansi.js";
import { BufferType } from "/state.js";
const Status = {
@ -29,10 +30,12 @@ export default function BufferHeader(props) {
var serverInfo = props.buffer.serverInfo;
description = `Connected to ${serverInfo.name}`;
} else if (props.buffer.topic) {
description = linkify(props.buffer.topic);
description = linkify(stripANSI(props.buffer.topic));
} else if (props.buffer.who) {
var who = props.buffer.who;
var realname = stripANSI(who.realname || "");
var status = Status.HERE;
if (who.away) {
status = Status.GONE;
@ -41,7 +44,7 @@ export default function BufferHeader(props) {
status = Status.OFFLINE;
}
description = html`<${NickStatus} status=${status}/> ${who.realname} (${who.username}@${who.hostname})`;
description = html`<${NickStatus} status=${status}/> ${realname} (${who.username}@${who.hostname})`;
} else if (props.buffer.offline) {
// User is offline, but we don't have WHO information
description = html`<${NickStatus} status=${Status.OFFLINE}/> ${props.buffer.name}`;

View file

@ -1,6 +1,7 @@
import { html, Component } from "/lib/index.js";
import linkify from "/lib/linkify.js";
import * as irc from "/lib/irc.js";
import { strip as stripANSI } from "/lib/ansi.js";
import { BufferType, getNickURL, getMessageURL } from "/state.js";
function djb2(s) {
@ -64,10 +65,10 @@ class LogLine extends Component {
var action = text.slice(actionPrefix.length, -1);
lineClass = "me-tell";
content = html`* ${createNick(msg.prefix.name)} ${linkify(action)}`;
content = html`* ${createNick(msg.prefix.name)} ${linkify(stripANSI(action))}`;
} else {
lineClass = "talk";
content = html`${"<"}${createNick(msg.prefix.name)}${">"} ${linkify(text)}`;
content = html`${"<"}${createNick(msg.prefix.name)}${">"} ${linkify(stripANSI(text))}`;
}
break;
case "JOIN":
@ -94,7 +95,7 @@ class LogLine extends Component {
case "TOPIC":
var topic = msg.params[1];
content = html`
${createNick(msg.prefix.name)} changed the topic to: ${linkify(topic)}
${createNick(msg.prefix.name)} changed the topic to: ${linkify(stripANSI(topic))}
`;
break;
default: