default.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. # This file is part of ranger, the console file manager.
  2. # License: GNU GPL version 3, see the file "AUTHORS" for details.
  3. from __future__ import absolute_import, division, print_function
  4. from ranger.gui.color import (BRIGHT, black, blue, bold, cyan, default,
  5. default_colors, dim, green, magenta, normal, red,
  6. reverse, white, yellow)
  7. from ranger.gui.colorscheme import ColorScheme
  8. class Default(ColorScheme):
  9. progress_bar_color = blue
  10. def use(self, context):
  11. fg, bg, attr = default_colors
  12. if context.reset:
  13. return default_colors
  14. elif context.in_browser:
  15. if context.selected:
  16. attr = reverse
  17. else:
  18. attr = normal
  19. if context.empty or context.error:
  20. bg = red
  21. if context.border:
  22. fg = blue
  23. if context.document:
  24. attr |= normal
  25. fg = magenta
  26. if context.media:
  27. if context.image:
  28. fg = yellow
  29. elif context.video:
  30. fg = red
  31. elif context.audio:
  32. fg = green
  33. else:
  34. fg = magenta
  35. if context.container:
  36. fg = red
  37. if context.directory:
  38. attr |= bold
  39. fg = blue
  40. fg += BRIGHT
  41. elif context.executable and not \
  42. any((context.media, context.container,
  43. context.fifo, context.socket)):
  44. attr |= bold
  45. fg = green
  46. fg += BRIGHT
  47. if context.socket:
  48. attr |= bold
  49. fg = magenta
  50. fg += BRIGHT
  51. if context.fifo or context.device:
  52. fg = yellow
  53. if context.device:
  54. attr |= bold
  55. fg += BRIGHT
  56. if context.link:
  57. fg = cyan if context.good else magenta
  58. if context.tag_marker and not context.selected:
  59. attr |= bold
  60. if fg in (red, magenta):
  61. fg = white
  62. else:
  63. fg = red
  64. fg += BRIGHT
  65. if not context.selected and (context.cut or context.copied):
  66. attr |= bold
  67. fg = black
  68. fg += BRIGHT
  69. # If the terminal doesn't support bright colors, use dim white
  70. # instead of black.
  71. if BRIGHT == 0:
  72. attr |= dim
  73. fg = white
  74. if context.main_column:
  75. # Doubling up with BRIGHT here causes issues because it's
  76. # additive not idempotent.
  77. if context.selected:
  78. attr |= bold
  79. if context.marked:
  80. attr |= bold
  81. fg = cyan
  82. if context.badinfo:
  83. if attr & reverse:
  84. bg = magenta
  85. else:
  86. fg = magenta
  87. if context.inactive_pane:
  88. fg = cyan
  89. elif context.in_titlebar:
  90. if context.hostname:
  91. fg = red if context.bad else green
  92. elif context.directory:
  93. fg = blue
  94. elif context.tab:
  95. if context.good:
  96. bg = green
  97. elif context.link:
  98. fg = blue
  99. attr |= bold
  100. elif context.in_statusbar:
  101. if context.permissions:
  102. if context.good:
  103. fg = cyan
  104. elif context.bad:
  105. fg = magenta
  106. if context.marked:
  107. attr |= bold | reverse
  108. fg = yellow
  109. fg += BRIGHT
  110. if context.frozen:
  111. attr |= bold | reverse
  112. fg = cyan
  113. fg += BRIGHT
  114. if context.message:
  115. if context.bad:
  116. attr |= bold
  117. fg = red
  118. fg += BRIGHT
  119. if context.loaded:
  120. bg = self.progress_bar_color
  121. if context.vcsinfo:
  122. fg = blue
  123. attr &= ~bold
  124. if context.vcscommit:
  125. fg = yellow
  126. attr &= ~bold
  127. if context.vcsdate:
  128. fg = cyan
  129. attr &= ~bold
  130. if context.text:
  131. if context.highlight:
  132. attr |= reverse
  133. if context.in_taskview:
  134. if context.title:
  135. fg = blue
  136. if context.selected:
  137. attr |= reverse
  138. if context.loaded:
  139. if context.selected:
  140. fg = self.progress_bar_color
  141. else:
  142. bg = self.progress_bar_color
  143. if context.vcsfile and not context.selected:
  144. attr &= ~bold
  145. if context.vcsconflict:
  146. fg = magenta
  147. elif context.vcsuntracked:
  148. fg = cyan
  149. elif context.vcschanged:
  150. fg = red
  151. elif context.vcsunknown:
  152. fg = red
  153. elif context.vcsstaged:
  154. fg = green
  155. elif context.vcssync:
  156. fg = green
  157. elif context.vcsignored:
  158. fg = default
  159. elif context.vcsremote and not context.selected:
  160. attr &= ~bold
  161. if context.vcssync or context.vcsnone:
  162. fg = green
  163. elif context.vcsbehind:
  164. fg = red
  165. elif context.vcsahead:
  166. fg = blue
  167. elif context.vcsdiverged:
  168. fg = magenta
  169. elif context.vcsunknown:
  170. fg = red
  171. return fg, bg, attr