Skip to content

Commit c3dbf5b

Browse files
committed
fix: dashboard Application Logs tail -f incorrectly splits newlines
we should just pass the raw buffer data directly to the xterm, so that it can handle cursor motion properly. e.g. moving cursors to previous lines, deleting lines...
1 parent ad34388 commit c3dbf5b

File tree

2 files changed

+15
-32
lines changed

2 files changed

+15
-32
lines changed

plugins/plugin-codeflare/src/components/Terminal.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ interface Props {
2727

2828
export default class XTerm extends React.PureComponent<Props> {
2929
private terminal: Terminal = new Terminal({
30+
convertEol: true,
3031
scrollback: 5000,
3132
})
3233

@@ -37,7 +38,7 @@ export default class XTerm extends React.PureComponent<Props> {
3738
this.mountTerminal()
3839

3940
if (this.props.on) {
40-
this.props.on("data", this.writeln)
41+
this.props.on("data", this.terminal.write.bind(this.terminal))
4142
}
4243
}
4344

@@ -50,12 +51,6 @@ export default class XTerm extends React.PureComponent<Props> {
5051
}
5152
}
5253

53-
private writeln = (data: any) => {
54-
if (typeof data === "string") {
55-
this.terminal.writeln(data)
56-
}
57-
}
58-
5954
private unmountTerminal() {
6055
if (this.terminal) {
6156
this.terminal.dispose()
@@ -78,8 +73,8 @@ export default class XTerm extends React.PureComponent<Props> {
7873

7974
if (this.props.initialContent) {
8075
// @starpit i don't know why we have to split the newlines...
81-
this.props.initialContent.split(/\n/).forEach(this.writeln)
82-
//this.terminal.write(this.props.initialContent)
76+
//this.props.initialContent.split(/\n/).forEach(this.writeln)
77+
this.terminal.write(this.props.initialContent)
8378
}
8479

8580
this.terminal.open(xtermContainer)

plugins/plugin-codeflare/src/controller/tailf.ts

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { Arguments, ReactResponse, Registrar, encodeComponent } from "@kui-shell/core"
17+
import { Arguments, Registrar, encodeComponent } from "@kui-shell/core"
1818

1919
import { expand } from "../lib/util"
2020
import { followFlags, FollowOptions } from "./dashboard"
@@ -32,29 +32,17 @@ async function tail(args: Arguments<FollowOptions>) {
3232
])
3333

3434
if (process.env.FOLLOW) {
35-
const [TailFile, split2] = await Promise.all([
36-
import("@logdna/tail-file").then((_) => _.default),
37-
import("split2").then((_) => _.default),
38-
])
35+
const TailFile = await import("@logdna/tail-file").then((_) => _.default)
36+
const tail = new TailFile(fp, { startPos: 0, pollFileIntervalMs: 500 })
37+
tail.start()
38+
tail.on("tail_error", (err) => console.error(err))
3939

40-
return new Promise<ReactResponse>((resolve, reject) => {
41-
try {
42-
const tail = new TailFile(fp, { startPos: 0, pollFileIntervalMs: 500 })
43-
tail.start()
44-
tail.on("tail_error", reject)
45-
46-
const splitter = tail.pipe(split2())
47-
48-
resolve({
49-
react: React.createElement(Terminal, {
50-
on: splitter.on.bind(splitter),
51-
unwatch: tail.quit.bind(tail),
52-
}),
53-
})
54-
} catch (err) {
55-
reject(err)
56-
}
57-
})
40+
return {
41+
react: React.createElement(Terminal, {
42+
on: tail.on.bind(tail),
43+
unwatch: tail.quit.bind(tail),
44+
}),
45+
}
5846
} else {
5947
const initialContent = await args.REPL.qexec<string>(`vfs fslice ${encodeComponent(fp)} 0`)
6048

0 commit comments

Comments
 (0)