• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

yast / yast-country / 15022004526

14 May 2025 01:29PM UTC coverage: 42.791% (-0.2%) from 43.025%
15022004526

Pull #328

github

web-flow
Merge f0e471a76 into 17e9fd3be
Pull Request #328: Load required "setxkbmap" package on demand (bsc#1243088)

1484 of 3468 relevant lines covered (42.79%)

12.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.21
/console/src/modules/Console.rb
1
# encoding: utf-8
2

3
# ------------------------------------------------------------------------------
4
# Copyright (c) 2012 Novell, Inc. All Rights Reserved.
5
#
6
#
7
# This program is free software; you can redistribute it and/or modify it under
8
# the terms of version 2 of the GNU General Public License as published by the
9
# Free Software Foundation.
10
#
11
# This program is distributed in the hope that it will be useful, but WITHOUT
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License along with
16
# this program; if not, contact Novell, Inc.
17
#
18
# To contact Novell about this file by physical or electronic mail, you may find
19
# current contact information at www.novell.com.
20
# ------------------------------------------------------------------------------
21

22
# File:
23
#        Console.ycp
24
#
25
# Module:
26
#        Console
27
#
28
# Depends:
29
#        Language
30
#
31
# Summary:
32
#        provide console specific stuff (esp. font and encoding)
33
#<BR>
34
# sysconfig /etc/sysconfig/console:<BR>
35
#<UL>
36
#<LI>        CONSOLE_FONT                string        console font</LI>
37
#<LI>        CONSOLE_SCREENMAP        string        console screenmap</LI>
38
#<LI>        CONSOLE_UNICODEMAP        string        console unicode map</LI>
39
#<LI>        CONSOLE_MAGIC                string        console magic control sequence</LI>
40
#<LI>        CONSOLE_ENCODING        string        console encoding</LI>
41
#</UL>
42
#
43
# $Id$
44
#
45
# Author:
46
#        Klaus Kaempf <kkaempf@suse.de>
47
#
48
require "yast"
1✔
49
require "json"
1✔
50
Yast.import "Directory"
1✔
51

52
module Yast
1✔
53
  class ConsoleClass < Module
1✔
54
    def main
1✔
55
      Yast.import "UI"
7✔
56

57
      Yast.import "Kernel"
7✔
58
      Yast.import "Mode"
7✔
59
      Yast.import "Language"
7✔
60
      Yast.import "Linuxrc"
7✔
61
      Yast.import "Encoding"
7✔
62
      Yast.import "Stage"
7✔
63
      Yast.import "OSRelease"
7✔
64

65
      # current base language, used in Check
66
      @language = "en_US"
7✔
67

68
      @font = "lat1-16.psfu"
7✔
69
      @unicodeMap = ""
7✔
70
      @screenMap = ""
7✔
71
      @magic = "(B"
7✔
72

73
      # non-empty if serial console
74
      # something like "ttyS0,9600" from /etc/install.inf
75
      @serial = ""
7✔
76

77
      # Console fonts map (used as cache for #consolefonts)
78
      @consolefonts = nil
7✔
79

80
      Console()
7✔
81
    end
82

83
    # activate a language specific console font
84
    #
85
    # @param        string        language        ISO code of language
86
    # @return        [String]        encoding        encoding for console i/o
87

88
    def SelectFont(lang)
1✔
89
      fqlanguage = Language.GetLocaleString(lang)
8✔
90

91
      consolefont = consolefonts[fqlanguage] || consolefonts[lang]
8✔
92
      if consolefont.nil? && lang.size > 2
8✔
93
        consolefont = consolefonts[lang[0,2]]
8✔
94
      end
95
      consolefont ||= []
8✔
96

97
      if !consolefont.empty?
8✔
98
        @language = lang
7✔
99

100
        @font = consolefont["font"]
7✔
101
        @unicodeMap = consolefont["unicodeMap"]
7✔
102
        @screenMap = consolefont["screenMap"]
7✔
103
        @magic = consolefont["magic"]
7✔
104

105
        currentLanguage = WFM.GetLanguage
7✔
106

107
        # Eventually must switch languages to get correct encoding
108
        if currentLanguage != @language
7✔
109
          currentEncoding = WFM.GetEncoding # save encoding
5✔
110

111
          Encoding.console = WFM.SetLanguage(@language) # switch lang, get proposed encoding
5✔
112

113
          WFM.SetLanguage(currentLanguage, currentEncoding) # reset as it was before
5✔
114
        end
115

116
        if Linuxrc.braille
7✔
117
          SCR.Execute(path(".target.bash"), "/usr/bin/setfont")
1✔
118
        elsif !Mode.commandline
6✔
119
          UI.SetConsoleFont(@magic, @font, @screenMap, @unicodeMap, @language)
6✔
120
        end
121
      end
122

123
      Builtins.y2milestone(
8✔
124
        "Language %1 -> Console encoding %2",
125
        @language,
126
        Encoding.console
127
      )
128
      Encoding.console
8✔
129
    end
130

131
    # save data to system (rc.config agent)
132

133
    def Save
1✔
134
      # writing vconsole.conf directly, no other API available ATM
135
      SCR.Write(path(".etc.vconsole_conf.FONT"), @font)
1✔
136
      SCR.Write(path(".etc.vconsole_conf.FONT_MAP"), @screenMap)
1✔
137
      SCR.Write(path(".etc.vconsole_conf.FONT_UNIMAP"), @unicodeMap)
1✔
138
      SCR.Write(path(".etc.vconsole_conf"), nil)
1✔
139

140
      SCR.Write(path(".sysconfig.console.CONSOLE_MAGIC"), @magic)
1✔
141

142
      SCR.Write(path(".sysconfig.console.CONSOLE_ENCODING"), WFM.GetEncoding)
1✔
143
      SCR.Write(
1✔
144
        path(".sysconfig.console.CONSOLE_ENCODING.comment"),
145
        "\n" +
146
          "# Encoding used for output of non-ascii characters.\n" +
147
          "#\n"
148
      )
149
      SCR.Write(path(".sysconfig.console"), nil)
1✔
150

151
      if @serial != ""
1✔
152
        # Root can login via console. See securetty(5)
153
        SCR.Execute(
×
154
          path(".target.bash"),
155
          "/usr/bin/grep -Ew ^console /etc/securetty || /usr/bin/echo console >> /etc/securetty"
156
        )
157
      end
158

159
      nil
1✔
160
    end
161

162
    # restore data to system (rc.config agent)
163
    # returns encoding
164
    def Restore
1✔
165
      @font = Misc.SysconfigRead(path(".etc.vconsole_conf.FONT"), "")
7✔
166
      @screenMap = Misc.SysconfigRead(path(".etc.vconsole_conf.FONT_MAP"), "")
7✔
167
      @unicodeMap = Misc.SysconfigRead(path(".etc.vconsole_conf.FONT_UNIMAP"), "")
7✔
168
      Builtins.y2milestone("vconsole.conf: FONT: %1, FONT_MAP: %2, FONT_UNIMAP: %3", @font, @screenMap, @unicodeMap)
7✔
169

170
      @magic = Convert.to_string(
7✔
171
        SCR.Read(path(".sysconfig.console.CONSOLE_MAGIC"))
172
      )
173
      @language = Language.GetCurrentLocaleString
7✔
174
      Builtins.y2milestone("encoding %1", Encoding.console)
7✔
175
      Encoding.console
7✔
176
    end
177

178
    # initialize console settings
179
    def Init
1✔
180
      if Linuxrc.braille
×
181
        SCR.Execute(path(".target.bash"), "/usr/bin/setfont")
×
182
      else
183
        UI.SetConsoleFont(@magic, @font, @screenMap, @unicodeMap, @language)
×
184
      end
185

186
      nil
×
187
    end
188

189
    # Check current configuration
190
    # This function should be called to check consistency with
191
    # other modules (mentioned as Depends in the header)
192
    # @return        0        if no change
193
    #                 1        change due to dependency with other module
194
    #                2        inconsistency detected
195
    #
196

197
    def Check
1✔
198
      true
×
199
    end
200

201
    # constructor
202
    # does nothing in initial mode
203
    # restores console configuration from /etc/sysconfig
204
    # in normal mode
205

206
    def Console
1✔
207
      if Stage.initial
7✔
208
        @serial = Linuxrc.InstallInf("Console")
×
209
        @serial = "" if @serial == nil
×
210
      else
211
        Restore()
7✔
212
      end
213

214
      nil
7✔
215
    end
216

217
    publish :function => :SelectFont, :type => "string (string)"
1✔
218
    publish :function => :Save, :type => "void ()"
1✔
219
    publish :function => :Restore, :type => "string ()"
1✔
220
    publish :function => :Init, :type => "void ()"
1✔
221
    publish :function => :Check, :type => "boolean ()"
1✔
222
    publish :function => :Console, :type => "void ()"
1✔
223

224
  private
1✔
225

226
    # Console fonts map
227
    #
228
    # Associates languages with the following set of properties: font, unicode map,
229
    # screen map and magic initialization.
230
    #
231
    # @example Console fonts format
232
    #   {
233
    #     "bg" => {
234
    #       "font"=>"UniCyr_8x16.psf",
235
    #       "unicodeMap"=>"",
236
    #       "screenMap"=>"trivial",
237
    #       "magic"=>"(K"
238
    #     },
239
    #     "bg_BG" => {
240
    #       "font"=>"UniCyr_8x16.psf",
241
    #       "unicodeMap"=>"",
242
    #       "screenMap"=>"trivial",
243
    #       "magic"=>"(K"
244
    #     }
245
    #   }
246
    #
247
    # @return [Hash] Console fonts map. See the example for content details.
248
    def consolefonts
1✔
249
      return @consolefonts if @consolefonts
24✔
250

251
      @consolefonts = JSON.load(File.read(Directory.find_data_file("consolefonts.json")))
6✔
252
    end
253
  end
254

255
  Console = ConsoleClass.new
1✔
256
  Console.main
1✔
257
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc