Programming

Terminal Code Highlight - pygmentize, highlight

hyunmini 2017. 3. 14. 13:22



포스팅하면서 코드 색깔 입히는 게 귀찮았는데 (몇몇 좋은 js 모듈이나 온라인 highligher 사이트가 있지만 편집하기가 생각보다 불편...)


터미널에서 쉽게 코드에 색을 입히는 프로그램을 찾아서 정리해 둔다. 


여러개 있는것 같지만 두가지만 정리.







highlight



$ brew install highlight



 hyunmini:cpp $ highlight -O ansi test.cpp

#include <iostream>

#include <fstream>

#include <map>

#include <string.h>


using namespace::std;


map<int,string> test1234;


int main(){

string myStr = "test";

cout << "test string: " << myStr << "(" << myStr.length() << endl;

map<int,string>::iterator it;

test1234.insert(pair<int,string>(0,"haha"));

test1234.insert(pair<int,string>(1,"222a"));

it = test1234.begin();

cout << (*it).first << endl;

cout << (*it).second << endl;

}







Pygments


pip install Pygments


$ pygmentize -g dbi.py


 hyunmini:frida $ pygmentize -g dbi.py

#!/usr/bin/python

#-*- coding: utf-8 -*-

import sys

import frida

import codecs


class Logger(object):

INFO = '\033[10m' # white

SUCC = '\033[92m' # green

WARN = '  \033[93m' # yellow

END = '\033[0m' # normal(white)


@staticmethod

def info(msg): # print console

print Logger.INFO + msg + Logger.END


@staticmethod

def succ(msg): # print console

print Logger.SUCC + msg + Logger.END


@staticmethod

def warn(msg): # print console







별칭 등록


hyunmini:frida $ alias

alias ccat='highlight -O ansi'

alias pcat='pygmentize -g'






끝~