From f3dd4eb420355cf5720dc0058a718867d18e8cbf Mon Sep 17 00:00:00 2001 From: Niklas Mischkulnig Date: Sat, 28 Apr 2018 22:14:09 +0200 Subject: [PATCH] Fix examples --- examples/event-loop.js | 13 ++++++------- examples/node-pad.js | 15 ++++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/examples/event-loop.js b/examples/event-loop.js index e512d00..79f7044 100644 --- a/examples/event-loop.js +++ b/examples/event-loop.js @@ -1,5 +1,6 @@ 'use strict'; const http = require('http'); +const os = require('os'); const libui = require('..'); let setIntervalHandle = null; @@ -20,7 +21,7 @@ const setIntervalMs = new libui.UiSlider(0, 1000); setIntervalMs.onChanged(setIntervalChanged); setIntervalMs.value = 0; -const sliderLabel = new libui.UiLabel("0"); +const sliderLabel = new libui.UiLabel('0'); sliderbox.append(setIntervalMs, 1); sliderbox.append(sliderLabel, 0); @@ -54,14 +55,12 @@ win.onClosing(() => { win.show(); libui.startLoop(); -const linebreak = process.platform === "win32" ? '\r\n' : '\n'; - function logAppend(line) { - const lines = log.text.split("\n"); - if (lines.length > 20) { - log.text = lines.slice(1).join(linebreak); + const lines = log.text.split('\n'); + if (lines.length > 25) { + log.text = lines.slice(1).join(os.EOL); } - log.append(line + linebreak); + log.append(line + os.EOL); } function setIntervalChanged() { diff --git a/examples/node-pad.js b/examples/node-pad.js index fbb70fe..6abdd2b 100644 --- a/examples/node-pad.js +++ b/examples/node-pad.js @@ -26,6 +26,7 @@ let currentFileName = ''; function newFile() { editor.text = ''; currentFileName = ''; + status.text = 'Not saved'; } function openFile() { @@ -39,7 +40,7 @@ function openFile() { err.stack); } editor.text = content; - status.text = `Open ${filename}`; + status.text = filename; currentFileName = filename; }); } @@ -48,6 +49,7 @@ function openFile() { function saveFileAs() { const filename = libui.UiDialogs.saveFile(win); if (filename) { + currentFileName = filename; writeFile(currentFileName, editor.text, err => { if (err) { return libui.UiDialogs.msgBoxError( @@ -55,7 +57,6 @@ function saveFileAs() { 'Error while writing file', err.stack); } - currentFileName = filename; }); } } @@ -87,10 +88,10 @@ menu([ label: 'Open', click: openFile }, - { - label: 'Close current tab', - click: () => {} - }, + // { + // label: 'Close current tab', + // click: () => {} + // }, { label: 'Save', click: saveFile @@ -140,7 +141,7 @@ win = window( tab( {stretchy: true}, (editor = multilineEntry({stretchy: true, tabTitle: 'New file'}))), - (status = label({stretchy: false, text: 'File not changed'}))); + (status = label({stretchy: false, text: 'Not saved'}))); win.show(); libui.startLoop();