Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: pream12989/dolphin
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: Devtrance/dolphin
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Mar 15, 2013

  1. bash colour codes to html in a string

    Banana committed Mar 15, 2013
    Copy the full SHA
    18deca9 View commit details
Showing with 60 additions and 0 deletions.
  1. +60 −0 single-functions/bash-terminal-colors-to-html.php
60 changes: 60 additions & 0 deletions single-functions/bash-terminal-colors-to-html.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

/**
* dolphin. Collection of useful PHP skeletons.
* Copyright (C) 2013 Johannes 'Banana' Keßler
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
*
* You should have received a copy of the
* COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
* along with this program. If not, see http://www.sun.com/cddl/cddl.html
*/


/**
* convert bash terminal color codes to html element with a css class
* works with this colour echo function: https://github.com/jumpin-banana/klimbim/blob/master/bash/colour-text-echo.sh
* eg. the $string as a direct return from the system call which return a string formatted with the above
* colour echo function.
*
* it can work with other functions but this is not tested.
*
* your can change the replace text with the html code you need. Also the css classes are needed.
*/
function bashColortoHtml($string) {
$ret = false;

if(!empty($string)) {
$_colorPattern = array(
'/\\033\[1;33m(.*?)\\033\[0m/s',
'/\\033\[0;31m(.*?)\\033\[0m/s',
'/\\033\[0;34m(.*?)\\033\[0m/s',
'/\\033\[0;36m(.*?)\\033\[0m/s',
'/\\033\[0;35m(.*?)\\033\[0m/s',
'/\\033\[0;33m(.*?)\\033\[0m/s',
'/\\033\[1;37m(.*?)\\033\[0m/s',
'/\\033\[0;30m(.*?)\\033\[0m/s',
'/\\033\[0;32m(.*?)\\033\[0m/s'
);
$_colorReplace = array(
'<span class="yellow">$1</span>',
'<span class="red">$1</span>',
'<span class="blue">$1</span>',
'<span class="cyan">$1</span>',
'<span class="purple">$1</span>',
'<span class="brown">$1</span>',
'<span class="white">$1</span>',
'<span class="black">$1</span>',
'<span class="green">$1</span>'
);

$ret = preg_replace($_colorPattern, $_colorReplace, $string);
}

return $ret;
}

?>