How to Adjust Pry Colors

How to adjust pry colors

Pry uses CodeRay for coloring, so you can put the following in your .pryrc file:

CodeRay.scan("example", :ruby).term # just to load necessary files

TERM_TOKEN_COLORS = {
:symbol => '1;31' # will make symbols bolded and light red on my terminal
}

module CodeRay
module Encoders
class Term < Encoder
# override old colors
TERM_TOKEN_COLORS.each_pair do |key, value|
TOKEN_COLORS[key] = value
end
end
end
end

You can see here all values that can be customized (not sure which one exactly is the one you mentioned, but shouldn't be hard to track down):
https://github.com/rubychan/coderay/blob/master/lib/coderay/encoders/terminal.rb

How can I use Ruby to colorize the text output to a terminal?

Colorize is my favorite gem! :-)

Check it out:

https://github.com/fazibear/colorize

Installation:

gem install colorize

Usage:

require 'colorize'

puts "I am now red".red
puts "I am now blue".blue
puts "Testing".yellow

Change the color of only one line

You can try with a dataframe for the colors and then assign them with scale_color_manual():

library(tidyverse)
#Data
datos <- structure(list(country_name = c("Argentina", "Bolivia", "Brazil",
"Chile", "Colombia", "Ecuador", "Paraguay", "Peru", "Uruguay",
"Argentina", "Bolivia", "Brazil", "Chile", "Colombia", "Ecuador",
"Paraguay", "Peru", "Uruguay", "Argentina", "Bolivia"), country_code = c("ARG",
"BOL", "BRA", "CHL", "COL", "ECU", "PRY", "PER", "URY", "ARG",
"BOL", "BRA", "CHL", "COL", "ECU", "PRY", "PER", "URY", "ARG",
"BOL"), year = c(1990L, 1990L, 1990L, 1990L, 1990L, 1990L, 1990L,
1990L, 1990L, 1991L, 1991L, 1991L, 1991L, 1991L, 1991L, 1991L,
1991L, 1991L, 1992L, 1992L), value = c(1, 1, 1, 1, 1, 1, 1, 1,
1, 1.08, 1.03, 0.997, 1.06, 1, 1.02, 1.01, 1, 1.03, 1.15, 1.03
)), row.names = c("1", "2", "3", "4", "5", "6", "7", "8", "9",
"10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"
), class = "data.frame")

Code:

#Create data palette
dfcolors <- data.frame(vec = unique(datos$country_name),color='gray',stringsAsFactors = F)
#Change color
dfcolors$color[dfcolors$vec=='Argentina']<-'blue'
#Plot
ggplot(datos,aes(x=factor(year),y=value,group=country_name, color =
country_name,label=country_code)) +
geom_line(size=1.25) +
geom_point()+
geom_text(data = . %>% group_by(country_name) %>% filter(year==max(year)),
nudge_x=0.1, hjust=0.5,vjust=(-0.5)) +
expand_limits(x = as.numeric(max(datos$year))-as.numeric(min(datos$year))+1) +
guides(colour=FALSE)+
scale_color_manual(values = dfcolors$color,labels=dfcolors$vec)

Output:

Sample Image



Related Topics



Leave a reply



Submit