1
0
Fork 0

Add ascii color conversion

This commit is contained in:
Gregory Eremin 2018-09-07 15:16:30 +02:00
parent 45cc50c371
commit f592145b60
3 changed files with 22 additions and 9 deletions

View File

@ -135,6 +135,14 @@
"color-convert": "^1.9.0" "color-convert": "^1.9.0"
} }
}, },
"ansi-to-html": {
"version": "0.6.6",
"resolved": "https://registry.npmjs.org/ansi-to-html/-/ansi-to-html-0.6.6.tgz",
"integrity": "sha512-90M/2sZna3OsoOEbSyXK46poFnlClBC53Rx6etNKQK7iShsX5fI5E/M9Ld6FurtLaxAWLuAPi0Jp8p3y5oAkxg==",
"requires": {
"entities": "^1.1.1"
}
},
"anymatch": { "anymatch": {
"version": "1.3.2", "version": "1.3.2",
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-1.3.2.tgz", "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-1.3.2.tgz",

View File

@ -3,6 +3,7 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"dependencies": { "dependencies": {
"ansi-to-html": "^0.6.6",
"react": "^16.5.0", "react": "^16.5.0",
"react-dom": "^16.5.0", "react-dom": "^16.5.0",
"react-router-dom": "^4.3.1", "react-router-dom": "^4.3.1",

View File

@ -5,10 +5,13 @@ import Timestamp from './timestamp.js'
import { api, httpGET, httpStreamGET } from '../http.js' import { api, httpGET, httpStreamGET } from '../http.js'
import './output.css' import './output.css'
let Convert = require('ansi-to-html')
let converter = new Convert()
export default class Output extends Component { export default class Output extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
this.state = {job: null, xhr: null} this.state = { job: null, xhr: null }
} }
componentWillReceiveProps(props) { componentWillReceiveProps(props) {
@ -38,7 +41,7 @@ export default class Output extends Component {
loadJobDetails(id) { loadJobDetails(id) {
httpGET(api("/jobs/" + id), httpGET(api("/jobs/" + id),
(status, body) => { (status, body) => {
this.setState({job: JSON.parse(body)}) this.setState({ job: JSON.parse(body) })
}, },
(error) => { (error) => {
console.log("Failed to load job details:", error) console.log("Failed to load job details:", error)
@ -54,6 +57,7 @@ export default class Output extends Component {
let xhr = httpStreamGET(api("/jobs/" + id + "/log"), let xhr = httpStreamGET(api("/jobs/" + id + "/log"),
(chunk) => { // Progress (chunk) => { // Progress
let target = this.refs["output"] let target = this.refs["output"]
chunk = converter.toHtml(chunk)
target.innerHTML += chunk.replace(/\n/g, "<br/>") target.innerHTML += chunk.replace(/\n/g, "<br/>")
this.autoScroll() this.autoScroll()
}, },
@ -64,15 +68,15 @@ export default class Output extends Component {
} }
// Reload job details // Reload job details
this.setState({xhr: null}) this.setState({ xhr: null })
this.loadJobDetails(id) this.loadJobDetails(id)
}, },
(error) => { (error) => {
let target = this.refs["output"] let target = this.refs["output"]
target.innerHTML = "Failed to fetch command log: "+ error target.innerHTML = "Failed to fetch command log: " + error
} }
) )
this.setState({xhr: xhr}) this.setState({ xhr: xhr })
} }
autoScroll() { autoScroll() {
@ -106,21 +110,21 @@ export default class Output extends Component {
return ( return (
<div className="job-details full"> <div className="job-details full">
<div className="item command"> <div className="item command">
<span className="command"><Link to={"/cmd/"+ details.command + "/jobs"}>{details.command}</Link></span> <span className="command"><Link to={"/cmd/" + details.command + "/jobs"}>{details.command}</Link></span>
{args} {args}
<span className="flags">{details.flags}</span> <span className="flags">{details.flags}</span>
</div> </div>
<div className="item id"> <div className="item id">
<div className="name">ID</div> <div className="name">ID</div>
<div className="val"><Link to={"/cmd/"+ details.command + "/jobs/"+ details.id}>{details.id}</Link></div> <div className="val"><Link to={"/cmd/" + details.command + "/jobs/" + details.id}>{details.id}</Link></div>
</div> </div>
<div className="item state"> <div className="item state">
<div className="name">Status</div> <div className="name">Status</div>
<div className={"val "+details.state}>{state}</div> <div className={"val " + details.state}>{state}</div>
</div> </div>
<div className="item user"> <div className="item user">
<div className="name">User</div> <div className="name">User</div>
<div className="val"><Link to={"/users/"+ details.user.id +"/jobs"}>{details.user.name}</Link></div> <div className="val"><Link to={"/users/" + details.user.id + "/jobs"}>{details.user.name}</Link></div>
</div> </div>
{this.renderStarted()} {this.renderStarted()}
{this.renderFinished()} {this.renderFinished()}