mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-25 23:11:02 +08:00
Merge remote-tracking branch 'LCTT/master'
This commit is contained in:
commit
371933f1d0
207
published/20200813 How to use printf to format output.md
Normal file
207
published/20200813 How to use printf to format output.md
Normal file
@ -0,0 +1,207 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (robsean)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12573-1.html)
|
||||
[#]: subject: (How to use printf to format output)
|
||||
[#]: via: (https://opensource.com/article/20/8/printf)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
如何使用 printf 来格式化输出
|
||||
======
|
||||
|
||||
> 来了解一下 printf ,一个神秘的、灵活的和功能丰富的函数,可以替换 echo、print 和 cout。
|
||||
|
||||
![](https://img.linux.net.cn/data/attachment/album/202009/02/001109wp3xdtr27xop25e7.jpg)
|
||||
|
||||
当我开始学习 Unix 时,我很早就接触到了 `echo` 命令。同样,我最初的 [Python][2] 课程也涉及到了 `print` 函数。再想起学习 C++ 和 [Java][2] 时学到 `cout` 和 `systemout`。似乎每种语言都骄傲地宣称拥有一种方便的单行输出方法,并生怕这种方式要过时一样宣传它。
|
||||
|
||||
但是当我翻开中级教程的第一页后,我遇到了 `printf`,一个晦涩难懂的、神秘莫测的,又出奇灵活的函数。本文一反向初学者隐藏 `printf` 这个令人费解的传统,旨在介绍这个不起眼的 `printf` 函数,并解释如何在几乎所有语言中使用它。
|
||||
|
||||
### printf 简史
|
||||
|
||||
术语 `printf` 代表“<ruby>格式化打印<rt>print formatted</rt></ruby>”,它可能最早出现 [Algol 68][3] 编程语言中。自从它被纳入到 C 语言后,`printf` 已经在 C++、Java、Bash、PHP 中一次次重新实现,并且很可能在你最喜欢的 “后 C” 语言中再次出现。
|
||||
|
||||
显然,它很受欢迎,但很多人认为它的语法很复杂,尤其是与 `echo` 或 `print` 或 `cout` 等替代的函数相比尤为明显。例如,这是在 Bash 中的一个简单的 `echo` 语句:
|
||||
|
||||
```
|
||||
$ echo hello
|
||||
hello
|
||||
$
|
||||
```
|
||||
|
||||
这是在 Bash 中使用 `printf` 得到同样结果:
|
||||
|
||||
```
|
||||
$ printf "%s\n" hello
|
||||
hello
|
||||
$
|
||||
```
|
||||
|
||||
但是所增加的复杂性反而让你拥有很多功能,这是为什么 `printf` 值得学习的确切原因。
|
||||
|
||||
### printf 输出
|
||||
|
||||
在 `printf` 背后的基本思想是:它能够基于与内容*分离的*样式信息来格式化输出。例如,这里是 `printf` 认可的视作特殊字符的特定序列集合。你喜欢的语言可能会有或多或少的序列,但是通常包含:
|
||||
|
||||
* `\n`: 新行
|
||||
* `\r`: 回车换行
|
||||
* `\t`: 水平制表符
|
||||
* `\NNN`: 一个包含一个到三个数字,使用八进制值表示的特殊字节
|
||||
|
||||
例如:
|
||||
|
||||
```
|
||||
$ printf "\t\123\105\124\110\n"
|
||||
SETH
|
||||
$
|
||||
```
|
||||
|
||||
在这个 Bash 示例中, `printf` 渲染一个制表符后,然后是分配给四个八进制值字符串的 ASCII 字符,并以一个生成一个新行(`\n`)的控制序列结束。
|
||||
|
||||
如果同样使用 `echo` 来输出会产生更多的字符:
|
||||
|
||||
```
|
||||
$ printf "\t\123\105\124\110\n"
|
||||
\t\123\105\124\110\n
|
||||
$
|
||||
```
|
||||
|
||||
使用 Python 的 `print` 函数来完成同样的任务,你会发现 Python 的 `print` 命令比你想象的要强大:
|
||||
|
||||
```
|
||||
>>> print("\t\123\n")
|
||||
S
|
||||
|
||||
>>>
|
||||
```
|
||||
|
||||
显然,Python 的 `print` 包含传统的 `printf` 特性以及简单的 `echo` 或 `cout` 的特性。
|
||||
|
||||
不过,这些示例包括的只是文字字符,尽管在某些情况下它们也很有用,但它们可能是 `printf` 最不重要的部分。`printf` 的真正的威力在于格式化说明。
|
||||
|
||||
### 使用 printf 格式化输出
|
||||
|
||||
格式化说明符是以一个百分号(`%`)开头的字符。
|
||||
|
||||
常见的格式化说明符包括:
|
||||
|
||||
* `%s`: 字符串
|
||||
* `%d`: 数字
|
||||
* `%f`: 浮点数字
|
||||
* `%o`: 一个八进制的数字
|
||||
|
||||
这些格式化说明符是 `printf` 语句的占位符,你可以使用一个在其它地方提供的值来替换你的 `printf` 语句中的占位符。这些值在哪里提供取决于你使用的语言和它的语法,这里有一个简单的 Java 例子:
|
||||
|
||||
```
|
||||
string var="hello\n";
|
||||
system.out.printf("%s", var);
|
||||
```
|
||||
|
||||
把这个代码包裹在适当的样板文件中,在执行后,将呈现:
|
||||
|
||||
```
|
||||
$ ./example
|
||||
hello
|
||||
$
|
||||
```
|
||||
|
||||
但是,当一个变量的内容更改时,有意思的地方就来了。假设你想基于不断增加的数字来更新输出:
|
||||
|
||||
```
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int var=0;
|
||||
while ( var < 100) {
|
||||
var++;
|
||||
printf("Processing is %d% finished.\n", var);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
编译并运行:
|
||||
|
||||
```
|
||||
Processing is 1% finished.
|
||||
[...]
|
||||
Processing is 100% finished.
|
||||
```
|
||||
|
||||
注意,在代码中的两个 `%` 将被解析为一个打印出来的 `%` 符号。
|
||||
|
||||
### 使用 printf 限制小数位数
|
||||
|
||||
数字也可以是很复杂,`printf` 提供很多格式化选项。你可以对浮点数使用 `%f` 限制打印出多少个小数位。通过把一个点(`.`)和一个限制的数放置在百分符号和 `f` 之间, 你可以告诉 `printf` 打印多少位小数。这是一个简单的用 Bash 写的简练示例:
|
||||
|
||||
```
|
||||
$ printf "%.2f\n" 3.141519
|
||||
3.14
|
||||
$
|
||||
```
|
||||
|
||||
类似的语法也适用于其它的语言。这里是一个 C 语言的示例:
|
||||
|
||||
```
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
fprintf(stdout, "%.2f\n", 4 * atan(1.0));
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
对于三位小数,使用 `.3f` ,依次类推。
|
||||
|
||||
### 使用 printf 来在数字上添加逗号
|
||||
|
||||
因为位数大的数字很难解读,所以通常使用一个逗号来断开大的数字。你可以在百分号和 `d` 之间放置一个撇号(`'`),让 `printf` 根据需要添加逗号:
|
||||
|
||||
```
|
||||
$ printf "%'d\n" 1024
|
||||
1,024
|
||||
$ printf "%'d\n" 1024601
|
||||
1,024,601
|
||||
$
|
||||
```
|
||||
|
||||
### 使用 printf 来添加前缀零
|
||||
|
||||
`printf` 的另一个常用的用法是对文件名称中的数字强制实行一种特定的格式。例如,如果你在一台计算机上有 10 个按顺序排列的文件,计算机可能会把 `10.jpg` 排在 `1.jpg` 之前,这可能不是你的本意。当你以编程的方式写一个到文件时,你可以使用 `printf` 来用前缀为 0 的字符形成文件名称。这是一个简单的用 Bash 写的简练示例:
|
||||
|
||||
```
|
||||
$ printf "%03d.jpg\n" {1..10}
|
||||
001.jpg
|
||||
002.jpg
|
||||
[...]
|
||||
010.jpg
|
||||
```
|
||||
|
||||
注意:每个数字最多使用 3 位数字。
|
||||
|
||||
### 使用 printf
|
||||
|
||||
正如这些 `printf` 示例所显示,包括控制字符,尤其是 `\n` ,可能会冗长,并且语法相对复杂。这就是为什么开发像 `echo` 和 `cout` 之类的快捷方式的原因。不过,如果你时不时地使用 `printf` ,你就会习惯于这种语法,并且它也会变成你的习惯。我不认为 `printf` 有任何理由成为你在日常活动中打印时的*首选*,但是它是一个很好的工具,当你需要它时,它不会拖累你。
|
||||
|
||||
花一些时间学习你所选择语言中的 `printf`,并且当你需要时就使用它。它是一个强有力的工具,你不会后悔随时可用的工具。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/8/printf
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[robsean](https://github.com/robsean)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/seth
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/coffee_tea_laptop_computer_work_desk.png?itok=D5yMx_Dr (Person drinking a hot drink at the computer)
|
||||
[2]: https://opensource.com/resources/python
|
||||
[3]: https://opensource.com/article/20/6/algol68
|
||||
[4]: http://www.opengroup.org/onlinepubs/009695399/functions/fprintf.html
|
||||
[5]: http://www.opengroup.org/onlinepubs/009695399/functions/atan.html
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (leommxj)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
@ -1,106 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Customize your GNOME desktop theme)
|
||||
[#]: via: (https://opensource.com/article/20/8/gnome-themes)
|
||||
[#]: author: (Alan Formy-Duval https://opensource.com/users/alanfdoss)
|
||||
|
||||
Customize your GNOME desktop theme
|
||||
======
|
||||
Use Tweaks and its user themes extension to change the look of your
|
||||
Linux UI.
|
||||
![Gnomes in a window.][1]
|
||||
|
||||
GNOME is a fairly simple and streamlined Linux graphical user interface (GUI), and a lot of users appreciate its minimalist look. Although it's pretty basic out of the box, you can customize [GNOME][2] to match your preferences. Thanks to GNOME Tweaks and the user themes extension, you can change the look and feel of the top bar, window title bars, icons, cursors, and many other UI options.
|
||||
|
||||
### Get started
|
||||
|
||||
Before you can change your GNOME theme, you have to install [Tweaks][3] and enable the user themes extension.
|
||||
|
||||
#### Install GNOME Tweaks
|
||||
|
||||
You can find Tweaks in the GNOME Software Center, where you can install it quickly with just the click of a button.
|
||||
|
||||
![Install Tweaks in Software Center][4]
|
||||
|
||||
(Alan Formy-Duval, [CC BY-SA 4.0][5])
|
||||
|
||||
If you prefer the command line, use your package manager. For instance, on Fedora or CentOS:
|
||||
|
||||
|
||||
```
|
||||
`$ sudo dnf install gnome-tweaks`
|
||||
```
|
||||
|
||||
On Debian or similar:
|
||||
|
||||
|
||||
```
|
||||
`$ sudo apt install gnome-tweaks`
|
||||
```
|
||||
|
||||
#### Enable user themes
|
||||
|
||||
To enable the user themes extension, launch Tweaks and select **Extensions**. Find **User themes** and click the slider to enable it.
|
||||
|
||||
![Enable User Themes Extension][6]
|
||||
|
||||
(Alan Formy-Duval, [CC BY-SA 4.0][5])
|
||||
|
||||
### Get a theme
|
||||
|
||||
Now that you've completed those prerequisites, you're ready to find and download some themes. A great site to find new themes is [GNOME-Look.org][7].
|
||||
|
||||
There's a list of theme categories on the left-hand side of the page. Once you find a theme you want, you need to download it. I downloaded the `.tar` file directly to the `.themes` directory under my home directory (you may need to create the directory first):
|
||||
|
||||
|
||||
```
|
||||
`$ mkdir ~/.themes`
|
||||
```
|
||||
|
||||
If you want all the machine's users to be able to use the theme, place it in `/usr/share/themes`.
|
||||
|
||||
|
||||
```
|
||||
`$ tar xvf theme_archive.tar.xz`
|
||||
```
|
||||
|
||||
Once you have downloaded the file, extract the archive. You can delete the `.tar.xz` file to save some disk space.
|
||||
|
||||
### Apply a theme
|
||||
|
||||
To apply your new theme, go to the **Appearance** section in Tweaks. Here, you can select different options for each aspect of your desktop.
|
||||
|
||||
![Apply a theme][8]
|
||||
|
||||
(Alan Formy-Duval, [CC BY-SA 4.0][5])
|
||||
|
||||
### Variety is the spice of life
|
||||
|
||||
Being able to personalize a computer desktop with different wallpaper, colors, fonts, and more has been a popular feature since the first graphical interfaces hit the market. GNOME Tweaks and the user themes extension enable this customization on the GNOME desktop environment on all the GNU/Linux operating systems where it is available. And the open source community continues to provide a wide range of themes, icons, fonts, and wallpapers that anyone can download, play with, and customize.
|
||||
|
||||
What are your favorite GNOME themes, and why do you like them? Please share in the comments.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/8/gnome-themes
|
||||
|
||||
作者:[Alan Formy-Duval][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/alanfdoss
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/custom_gnomes.png?itok=iG98iL8d (Gnomes in a window.)
|
||||
[2]: https://www.gnome.org/
|
||||
[3]: https://wiki.gnome.org/Apps/Tweaks
|
||||
[4]: https://opensource.com/sites/default/files/uploads/gnome-install_tweaks_gui.png (Install Tweaks in Software Center)
|
||||
[5]: https://creativecommons.org/licenses/by-sa/4.0/
|
||||
[6]: https://opensource.com/sites/default/files/uploads/gnome-enable_user_theme_extension.png (Enable User Themes Extension)
|
||||
[7]: https://www.gnome-look.org
|
||||
[8]: https://opensource.com/sites/default/files/uploads/gnome-apply_theme.png (Apply a theme)
|
@ -1,5 +1,5 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
288
sources/tech/20200901 Create a mobile app with Flutter.md
Normal file
288
sources/tech/20200901 Create a mobile app with Flutter.md
Normal file
@ -0,0 +1,288 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Create a mobile app with Flutter)
|
||||
[#]: via: (https://opensource.com/article/20/9/mobile-app-flutter)
|
||||
[#]: author: (Vitaly Kuprenko https://opensource.com/users/kooper)
|
||||
|
||||
Create a mobile app with Flutter
|
||||
======
|
||||
Start your journey toward cross-platform development with the popular
|
||||
Flutter framework.
|
||||
![A person looking at a phone][1]
|
||||
|
||||
[Flutter][2] is a popular project among mobile developers around the world. The framework has a massive, friendly community of enthusiasts, which continues to grow as Flutter helps programmers take their projects into the mobile space.
|
||||
|
||||
This tutorial is meant to help you start doing mobile development with Flutter. After reading it, you'll know how to quickly install and set up the framework to start coding for smartphones, tablets, and other platforms.
|
||||
|
||||
This how-to assumes you have [Android Studio][3] installed on your computer and some experience working with it.
|
||||
|
||||
### What is Flutter?
|
||||
|
||||
Flutter enables developers to build apps for several platforms, including:
|
||||
|
||||
* Android
|
||||
* iOS
|
||||
* Web (in beta)
|
||||
* macOS (in development)
|
||||
* Linux (in development)
|
||||
|
||||
|
||||
|
||||
Support for macOS and Linux is in early development, while web support is expected to be released soon. This means that you can try out its capabilities now (as I'll describe below).
|
||||
|
||||
### Install Flutter
|
||||
|
||||
I'm using Ubuntu 18.04, but the installation process is similar with other Linux distributions, such as Arch or Mint.
|
||||
|
||||
#### Install with snapd
|
||||
|
||||
To install Flutter on Ubuntu or similar distributions using [snapd][4], enter this in a terminal:
|
||||
|
||||
|
||||
```
|
||||
$ sudo snap install flutter --classic
|
||||
|
||||
$ sudo snap install flutter –classic
|
||||
flutter 0+git.142868f from flutter Team/ installed
|
||||
```
|
||||
|
||||
Then launch it using the `flutter` command. Upon the first launch, the framework downloads to your computer:
|
||||
|
||||
|
||||
```
|
||||
$ flutter
|
||||
Initializing Flutter
|
||||
Downloading <https://storage.googleapis.com/flutter\_infra\[...\]>
|
||||
```
|
||||
|
||||
Once the download is finished, you'll see a message telling you that Flutter is initialized:
|
||||
|
||||
![Flutter initialized][5]
|
||||
|
||||
(Vitaly Kuprenko, [CC BY-SA 4.0][6])
|
||||
|
||||
#### Install manually
|
||||
|
||||
If you don't have snapd or your distribution isn't Ubuntu, the installation process will be a little bit different. In that case, [download][7] the version of Flutter recommended for your operating system.
|
||||
|
||||
![Install Flutter manually][8]
|
||||
|
||||
(Vitaly Kuprenko, [CC BY-SA 4.0][6])
|
||||
|
||||
Then extract it to your home directory.
|
||||
|
||||
Open the `.bashrc` file in your home directory (or `.zshrc` if you use the [Z shell][9]) in your favorite text editor. Because it's a hidden file, you must first enable showing hidden files in your file manager or open it from a terminal with:
|
||||
|
||||
|
||||
```
|
||||
`$ gedit ~/.bashrc &`
|
||||
```
|
||||
|
||||
Add the following line to the end of the file:
|
||||
|
||||
|
||||
```
|
||||
`export PATH="$PATH:~/flutter/bin"`
|
||||
```
|
||||
|
||||
Save and close the file. Keep in mind that if you extracted Flutter somewhere other than your home directory, the [path to Flutter SDK][10] will be different.
|
||||
|
||||
Close your terminal and then open it again so that your new configuration loads. Alternatively, you can source the configuration with:
|
||||
|
||||
|
||||
```
|
||||
`$ . ~/.bashrc`
|
||||
```
|
||||
|
||||
If you don't see an error, then everything is fine.
|
||||
|
||||
This installation method is a little bit harder than using the `snap` command, but it's pretty versatile and lets you install the framework on almost any distribution.
|
||||
|
||||
#### Check the installation
|
||||
|
||||
To check the result, enter the following in the terminal:
|
||||
|
||||
|
||||
```
|
||||
`flutter doctor -v`
|
||||
```
|
||||
|
||||
You'll see information about installed components. Don't worry if you see errors. You haven't installed any IDE plugins for working with Flutter SDK yet.
|
||||
|
||||
![Checking Flutter installation with the doctor command][11]
|
||||
|
||||
(Vitaly Kuprenko, [CC BY-SA 4.0][6])
|
||||
|
||||
### Install IDE plugins
|
||||
|
||||
You should install plugins in your [integrated development environment (IDE)][12] to help it interface with the Flutter SDK, interact with devices, and build code.
|
||||
|
||||
The three main IDE tools that are commonly used for Flutter development are IntelliJ IDEA (Community Edition), Android Studio, and VS Code (or [VSCodium][13]). I'm using Android Studio in this tutorial, but the steps are similar to how they work on IntelliJ IDEA (Community Edition) since they're built on the same platform.
|
||||
|
||||
First, launch **Android Studio**. Open **Settings** and go to the **Plugins** pane, and select the **Marketplace** tab. Enter **Flutter** in the search line and click **Install**.
|
||||
|
||||
![Flutter plugins][14]
|
||||
|
||||
(Vitaly Kuprenko, [CC BY-SA 4.0][6])
|
||||
|
||||
You'll probably see an option to install the **Dart** plugin; agree to it. If you don't see the Dart option, then install it manually by repeating the steps above. I also recommend using the **Rainbow Brackets** plugin, which makes code navigation easier.
|
||||
|
||||
That's it! You've installed all the plugins you need. You can check by entering a familiar command in the terminal:
|
||||
|
||||
|
||||
```
|
||||
`flutter doctor -v`
|
||||
```
|
||||
|
||||
![Checking Flutter plugins with the doctor command][15]
|
||||
|
||||
(Vitaly Kuprenko, [CC BY-SA 4.0][6])
|
||||
|
||||
### Build your "Hello World" application
|
||||
|
||||
To start a new project, create a Flutter project:
|
||||
|
||||
1. Select **New -> New Flutter project**.
|
||||
|
||||
![Creating a new Flutter plugin][16]
|
||||
|
||||
(Vitaly Kuprenko, [CC BY-SA 4.0][6])
|
||||
|
||||
2. In the window, choose the type of project you want. In this case, you need **Flutter Application**.
|
||||
|
||||
3. Name your project **hello_world**. Note that you should use a merged name, so use an underscore instead of a space. You may also need to specify the path to the SDK.
|
||||
|
||||
![Naming a new Flutter plugin][17]
|
||||
|
||||
(Vitaly Kuprenko, [CC BY-SA 4.0][6])
|
||||
|
||||
4. Enter the package name.
|
||||
|
||||
|
||||
|
||||
|
||||
You've created a project! Now you can launch it on a device or by using an emulator.
|
||||
|
||||
![Device options in Flutter][18]
|
||||
|
||||
(Vitaly Kuprenko, [CC BY-SA 4.0][6])
|
||||
|
||||
Select the device you want and press **Run**. In a moment, you will see the result.
|
||||
|
||||
![Flutter demo on mobile device][19]
|
||||
|
||||
(Vitaly Kuprenko, [CC BY-SA 4.0][6])
|
||||
|
||||
Now you can start working on an [intermediate project][20].
|
||||
|
||||
### Try Flutter for web
|
||||
|
||||
Before you install Flutter components for the web, you should know that Flutter's support for web apps is pretty raw at the moment. So it's not a good idea to use it for complicated projects yet.
|
||||
|
||||
Flutter for web is not active in the basic SDK by default. To switch it on, go to the beta channel. To do this, enter the following command in the terminal:
|
||||
|
||||
|
||||
```
|
||||
`flutter channel beta`
|
||||
```
|
||||
|
||||
![flutter channel beta output][21]
|
||||
|
||||
(Vitaly Kuprenko, [CC BY-SA 4.0][6])
|
||||
|
||||
Next, upgrade Flutter according to the beta branch by using the command:
|
||||
|
||||
|
||||
```
|
||||
`flutter upgrade`
|
||||
```
|
||||
|
||||
![flutter upgrade output][22]
|
||||
|
||||
(Vitaly Kuprenko, [CC BY-SA 4.0][6])
|
||||
|
||||
To make Flutter for web work, enter:
|
||||
|
||||
|
||||
```
|
||||
`flutter config --enable-web`
|
||||
```
|
||||
|
||||
Restart your IDE; this helps Android Studio index the new IDE and reload the list of devices. You should see several new devices:
|
||||
|
||||
![Flutter for web device options][23]
|
||||
|
||||
(Vitaly Kuprenko, [CC BY-SA 4.0][6])
|
||||
|
||||
Selecting **Chrome** launches an app in the browser, while **Web Server** gives you the link to your web app, which you can open in any browser.
|
||||
|
||||
Still, it's not time to rush into development because your current project doesn't support the web. To improve it, open the terminal in the project's root and enter:
|
||||
|
||||
|
||||
```
|
||||
`flutter create`
|
||||
```
|
||||
|
||||
This command recreates the project, adding web support. The existing code won't be deleted.
|
||||
|
||||
Note that the tree has changed and now has a "web" directory:
|
||||
|
||||
![File tree with web directory][24]
|
||||
|
||||
(Vitaly Kuprenko, [CC BY-SA 4.0][6])
|
||||
|
||||
Now you can get to work. Select **Chrome** and press **Run**. In a moment, you'll see the browser window with your app.
|
||||
|
||||
![Flutter web app demo][25]
|
||||
|
||||
(Vitaly Kuprenko, [CC BY-SA 4.0][6])
|
||||
|
||||
Congratulations! You've just launched a project for the browser and can continue working with it as with any other website.
|
||||
|
||||
All of this comes from the same codebase because Flutter makes it possible to write code for both mobile platforms and the web with little to no changes.
|
||||
|
||||
### Do more with Flutter
|
||||
|
||||
Flutter is a powerful tool for mobile development, and moreover, it's an important evolutionary step toward cross-platform development. Learn it, use it, and deliver your apps to all the platforms!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/9/mobile-app-flutter
|
||||
|
||||
作者:[Vitaly Kuprenko][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/kooper
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/idea_innovation_mobile_phone.png?itok=RqVtvxkd (A person looking at a phone)
|
||||
[2]: https://flutter.dev/
|
||||
[3]: https://developer.android.com/studio
|
||||
[4]: https://snapcraft.io/docs/getting-started
|
||||
[5]: https://opensource.com/sites/default/files/uploads/flutter1_initialized.png (Flutter initialized)
|
||||
[6]: https://creativecommons.org/licenses/by-sa/4.0/
|
||||
[7]: https://flutter.dev/docs/get-started/install/linux
|
||||
[8]: https://opensource.com/sites/default/files/uploads/flutter2_manual-install.png (Install Flutter manually)
|
||||
[9]: https://opensource.com/article/19/9/getting-started-zsh
|
||||
[10]: https://opensource.com/article/17/6/set-path-linux
|
||||
[11]: https://opensource.com/sites/default/files/uploads/flutter3_doctor.png (Checking Flutter installation with the doctor command)
|
||||
[12]: https://www.redhat.com/en/topics/middleware/what-is-ide
|
||||
[13]: https://opensource.com/article/20/6/open-source-alternatives-vs-code
|
||||
[14]: https://opensource.com/sites/default/files/uploads/flutter4_plugins.png (Flutter plugins)
|
||||
[15]: https://opensource.com/sites/default/files/uploads/flutter5_plugincheck.png (Checking Flutter plugins with the doctor command)
|
||||
[16]: https://opensource.com/sites/default/files/uploads/flutter6_newproject.png (Creating a new Flutter plugin)
|
||||
[17]: https://opensource.com/sites/default/files/uploads/flutter7_projectname.png (Naming a new Flutter plugin)
|
||||
[18]: https://opensource.com/sites/default/files/uploads/flutter8_launchflutter.png (Device options in Flutter)
|
||||
[19]: https://opensource.com/sites/default/files/uploads/flutter9_demo.png (Flutter demo on mobile device)
|
||||
[20]: https://opensource.com/article/18/6/flutter
|
||||
[21]: https://opensource.com/sites/default/files/uploads/flutter10_beta.png (flutter channel beta output)
|
||||
[22]: https://opensource.com/sites/default/files/uploads/flutter11_upgrade.png (flutter upgrade output)
|
||||
[23]: https://opensource.com/sites/default/files/uploads/flutter12_new-devices.png (Flutter for web device options)
|
||||
[24]: https://opensource.com/sites/default/files/uploads/flutter13_tree.png (File tree with web directory)
|
||||
[25]: https://opensource.com/sites/default/files/uploads/flutter14_webapp.png (Flutter web app demo)
|
@ -1,222 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (robsean)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to use printf to format output)
|
||||
[#]: via: (https://opensource.com/article/20/8/printf)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
如何使用 printf 来格式化输出
|
||||
======
|
||||
开始了解 printf ,一个神秘的,灵活的,和功能丰满的可替换 echo, print,和 cout 的函数。
|
||||
|
||||
![在计算机前喝热饮料][1]
|
||||
|
||||
当我开始学习 Unix 时,在很早的过程中,我就被介绍尝试 `echo` 命令。同样在很早的过程中,我最初的 [Python][2] 课程介绍 `print` 函数。拾起 C++ 和 [Java][2] 介绍给我的 `cout` 和 `systemout`。似乎每种语言都很自豪地有一个简单的一行产生输出的方法,并且被宣告这种方法的样式过时了。
|
||||
|
||||
但是在我翻开中级教程的第一页后,我遇到了 `printf`,一个晦涩难懂的,诡秘的,和出奇灵活的函数。违背了向初学者隐藏 `printf` 这个令人迷惑的传统,这篇文章旨在介绍不起眼的 `printf` 函数,并解释如何在近乎任意语言中使用它。
|
||||
|
||||
### printf 简史
|
||||
|
||||
术语 `printf` 代表 "格式化输出",可能在 [Algol 68][3] 编程语言中首次出现。自从它包含在 C 中,`printf` 已经在 C++,Java,Bash,PHP 中被重新实施,并且很可能在发生在你最喜欢的 ( C 衍生) 语言中。
|
||||
|
||||
它显然是很受欢迎,并且还有很多人认为它的语法很复杂,尤其是与 `echo` 或 `print` 或 `cout` 等可替代函数相比尤为明显。例如,在 Bash 中有一个简单的 echo 语句:
|
||||
|
||||
|
||||
```
|
||||
$ echo hello
|
||||
hello
|
||||
$
|
||||
```
|
||||
|
||||
在 Bash 中使用 `printf` 有相同的结果:
|
||||
|
||||
|
||||
```
|
||||
$ printf "%s\n" hello
|
||||
hello
|
||||
$
|
||||
```
|
||||
|
||||
但是所增加的复杂性反而让你拥有很多功能,这是为什么 `printf` 值得学习的确切原因。
|
||||
|
||||
### printf 输出
|
||||
|
||||
在 `printf` 背后的主要概念是:它能够基于来自内容的 _单独的_ 样式信息来格式化输出。例如,这里是 `printf` 认可的作为特殊字符的排列顺序的收藏品。你最喜欢的语言可能有更多一些或更少一些排列顺序,但是通常包含:
|
||||
|
||||
* `\n`: 新行
|
||||
* `\r`: 换行
|
||||
* `\t`: 水平制表符
|
||||
* `\NNN`: 一个使用八进制值的包含一个到三个数字的特殊字节
|
||||
|
||||
|
||||
|
||||
例如:
|
||||
|
||||
|
||||
```
|
||||
$ printf "\t\123\105\124\110\n"
|
||||
SETH
|
||||
$
|
||||
```
|
||||
|
||||
在这个 Bash 示例中, `printf` 在 ASCII 分配到四个八进制值的字符串的字符后渲染一个制表符。使用控制排列顺序来中止行,并生成一个新行 (`\n`) 。
|
||||
|
||||
使用 `echo` 来尝试相同的东西来生成一点儿完完全全的东西:
|
||||
|
||||
|
||||
```
|
||||
$ printf "\t\123\105\124\110\n"
|
||||
\t\123\105\124\110\n
|
||||
$
|
||||
```
|
||||
|
||||
对于相同是任务,使用 Python 的 `print` 函数,你会发现 Python 的 `print` 命令有你可以期待的更多的东西:
|
||||
|
||||
|
||||
```
|
||||
>>> print("\t\123\n")
|
||||
S
|
||||
|
||||
>>>
|
||||
```
|
||||
|
||||
显然,Python 的 `print` 包含传统的 `printf` 功能以及简单的 `echo` 或 `cout` 的功能。
|
||||
|
||||
不过,这些示例只包括字面意义上的字符,虽然在一些情况下它们也很有用,它们可能是 `printf` 最不重要的部分。`printf` 的真正的威力在于格式化规范。
|
||||
|
||||
### 使用 printf 格式化输出
|
||||
|
||||
格式化说明符是以一个百分号(`%`)开头的字符。
|
||||
常见的格式化说明符包括:
|
||||
|
||||
* `%s`: 字符串
|
||||
* `%d`: 数字
|
||||
* `%f`: 浮点数字
|
||||
* `%o`: 一个八进制的数字
|
||||
|
||||
|
||||
|
||||
这些格式化说明符在一个 `printf` 语句中是占位符,在你的`printf`语句中,你可以使用一个你在其它地方中提供的值来替换。但是这些提供的值取决于你正在使用的语言及其语法,这里是一个简单的 Java 示例:
|
||||
|
||||
|
||||
```
|
||||
string var="hello\n";
|
||||
system.out.printf("%s", var);
|
||||
```
|
||||
|
||||
这个包裹在适当的样板文件中的代码,在执行后,将呈现:
|
||||
|
||||
|
||||
```
|
||||
$ ./example
|
||||
hello
|
||||
$
|
||||
```
|
||||
|
||||
但是,当一个变量的内容更改时,它将会更加有趣。假设你想更新基于不断增加数字的输出:
|
||||
|
||||
|
||||
```
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int var=0;
|
||||
while ( var < 100) {
|
||||
var++;
|
||||
printf("Processing is %d% finished.\n", var);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
编译和运行:
|
||||
|
||||
|
||||
```
|
||||
Processing is 1% finished.
|
||||
[...]
|
||||
Processing is 100% finished.
|
||||
```
|
||||
|
||||
注意,在代码中的两个 `%` 分解为一个打印的 `%` 符号。
|
||||
|
||||
### 使用 printf 限制小数位数
|
||||
|
||||
数字可能会变得复杂,`printf` 提供很多格式化选项。你可以对浮点数使用 `%f` 限制打印出多少个小数位。通过把一个点 (`.`)和一个限制的数放置在百分符号和 `f` 之间, 你将告诉 `printf` 渲染多少位小数。这是一个简单的用 Bash 写的简练示例 :
|
||||
|
||||
|
||||
```
|
||||
$ printf "%.2f\n" 3.141519
|
||||
3.14
|
||||
$
|
||||
```
|
||||
|
||||
类似的语法也适用于其它的语言。这里是一个 C 语言的示例:
|
||||
|
||||
|
||||
```
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
fprintf(stdout, "%.2f\n", 4 * atan(1.0));
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
对于三位小数,使用 `.3f` ,依次类推。
|
||||
|
||||
### 使用 printf 来在数字上添加逗号
|
||||
|
||||
因为位数大的数字很难分解,所以通常使用一个逗号来断开大的数字。你可以根据需要在由 `printf` 组成的百分号和`d` 之间放置一个撇号(`'`) :
|
||||
|
||||
|
||||
```
|
||||
$ printf "%'d\n" 1024
|
||||
1,024
|
||||
$ printf "%'d\n" 1024601
|
||||
1,024,601
|
||||
$
|
||||
```
|
||||
|
||||
### 使用 printf 来添加前缀零
|
||||
|
||||
Another common use for `printf` 的另一个常用的用法是对文件名称中的数字强制实行一种特定的格式。例如,如果你在一台计算机上有 10 个按顺序排列的文件,该计算机可能会把 `10.jpg` 排在before `1.jpg` 之前,这可能不是你的本意。当你以编程的方式写一个到文件时,你可以使用 `printf` 来用前缀为0的字符来构成文件名称。这是一个简单的用 Bash 写的简练示例:
|
||||
|
||||
|
||||
```
|
||||
$ printf "%03d.jpg\n" {1..10}
|
||||
001.jpg
|
||||
002.jpg
|
||||
[...]
|
||||
010.jpg
|
||||
```
|
||||
|
||||
注意:每个数字最多使用 3 位数字。
|
||||
|
||||
### 使用 printf
|
||||
|
||||
正如这些 `printf` 示例所显示,包括控制字符,尤其是 `\n` ,可能会冗长,并且语法是相当地复杂。这就是为什么开发像 `echo` 和 `cout` 之类的快捷方式的原因。不过,如果你是不是地使用 `printf` ,你将会习惯于语法,并且它也将变成你的后天本性。,我看不出任何理由让 `printf` 成为你在日常活动中打印时的 _第一_ 选择,但是它是一个极好的工具来让你足够舒适,当你需要它时,将不会让你降低速度。
|
||||
|
||||
花一些时间学习你所选择语言中的 `printf` ,并且当你需要它时就使用它。它是一个强有力的你不会忘记的随时可用的工具。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/8/printf
|
||||
|
||||
作者:[Seth Kenlon][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[robsean](https://github.com/robsean)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/seth
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/coffee_tea_laptop_computer_work_desk.png?itok=D5yMx_Dr (Person drinking a hot drink at the computer)
|
||||
[2]: https://opensource.com/resources/python
|
||||
[3]: https://opensource.com/article/20/6/algol68
|
||||
[4]: http://www.opengroup.org/onlinepubs/009695399/functions/fprintf.html
|
||||
[5]: http://www.opengroup.org/onlinepubs/009695399/functions/atan.html
|
105
translated/tech/20200826 Customize your GNOME desktop theme.md
Normal file
105
translated/tech/20200826 Customize your GNOME desktop theme.md
Normal file
@ -0,0 +1,105 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Customize your GNOME desktop theme)
|
||||
[#]: via: (https://opensource.com/article/20/8/gnome-themes)
|
||||
[#]: author: (Alan Formy-Duval https://opensource.com/users/alanfdoss)
|
||||
|
||||
自定义你的 GNOME 桌面主题
|
||||
======
|
||||
使用 Tweaks 和它的用户主题扩展来改变你的 Linux UI。
|
||||
![Gnomes in a window.][1]
|
||||
|
||||
GNOME 是一个相当简单和精简的 Linux 图形用户界面 (GUI),很多用户喜欢它的简约外观。虽然它初始非常基本,但你可以根据自己的喜好来定制 [GNOME][2] 。多亏了 GNOME Tweaks 和用户主题扩展,你可以改变顶部栏、窗口标题栏、图标、光标和许多其他 UI 选项的外观。
|
||||
|
||||
### 开始使用
|
||||
|
||||
在你改变你的 GNOME 主题之前,你必须安装 [Tweaks][3] 并启用用户主题扩展。
|
||||
|
||||
#### 安装 GNOME Tweaks
|
||||
|
||||
你可以在 GNOME 软件中心找到 Tweaks,只需点击一个按钮就可以快速安装。
|
||||
|
||||
![Install Tweaks in Software Center][4]
|
||||
|
||||
(Alan Formy-Duval, [CC BY-SA 4.0][5])
|
||||
|
||||
如果你喜欢命令行,请使用你的软件包管理器。例如,在 Fedora 或 CentOS 上:
|
||||
|
||||
|
||||
```
|
||||
`$ sudo dnf install gnome-tweaks`
|
||||
```
|
||||
|
||||
在 Debian 或类似的发行版:
|
||||
|
||||
|
||||
```
|
||||
`$ sudo apt install gnome-tweaks`
|
||||
```
|
||||
|
||||
#### 启用用户主题
|
||||
|
||||
要启用用户主题扩展,启动 Tweaks 并选择 **Extensions**。找到 **User themes**,点击滑块启用。
|
||||
|
||||
![Enable User Themes Extension][6]
|
||||
|
||||
(Alan Formy-Duval, [CC BY-SA 4.0][5])
|
||||
|
||||
### 获取主题
|
||||
|
||||
现在你已经完成了这些预先条件,你已经准备好寻找和下载一些主题了。一个寻找新主题的好网站是 [GNOME-Look.org][7]。
|
||||
|
||||
在页面的左侧有一个主题类别的列表。当你找到一个你想要的主题,你需要下载它。我直接把 `.tar` 文件下载到我的家目录下的 `.themes` 目录(你可能需要先创建这个目录)。
|
||||
|
||||
|
||||
```
|
||||
`$ mkdir ~/.themes`
|
||||
```
|
||||
|
||||
如果你想让所有用户都能使用这个主题,请把它放在 `/usr/share/themes` 中。
|
||||
|
||||
|
||||
```
|
||||
`$ tar xvf theme_archive.tar.xz`
|
||||
```
|
||||
|
||||
下载后,解压压缩包。你可以删除 `.tar.xz` 文件以节省一些磁盘空间。
|
||||
|
||||
### 应用主题
|
||||
|
||||
要应用你的新主题,在 Tweaks 中进入 **Appearance**。在这里,你可以为你的桌面的每个方面选择不同的选项。
|
||||
|
||||
![Apply a theme][8]
|
||||
|
||||
(Alan Formy-Duval, [CC BY-SA 4.0][5])
|
||||
|
||||
### 多样性是生活的调剂品。
|
||||
|
||||
自从第一个图形界面面市以来,能够用不同的墙纸、颜色、字体等个性化电脑桌面一直是一个受欢迎的功能。GNOME Tweaks 和用户主题扩展使这种自定义功能能够在所有 GNU/Linux 操作系统上的 GNOME 桌面环境中实现。而且开源社区还在继续提供广泛的主题、图标、字体和壁纸,任何人都可以下载、尝试和定制。
|
||||
|
||||
你最喜欢的 GNOME 主题是什么,你为什么喜欢它们?请在评论中分享。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/8/gnome-themes
|
||||
|
||||
作者:[Alan Formy-Duval][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/alanfdoss
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/custom_gnomes.png?itok=iG98iL8d (Gnomes in a window.)
|
||||
[2]: https://www.gnome.org/
|
||||
[3]: https://wiki.gnome.org/Apps/Tweaks
|
||||
[4]: https://opensource.com/sites/default/files/uploads/gnome-install_tweaks_gui.png (Install Tweaks in Software Center)
|
||||
[5]: https://creativecommons.org/licenses/by-sa/4.0/
|
||||
[6]: https://opensource.com/sites/default/files/uploads/gnome-enable_user_theme_extension.png (Enable User Themes Extension)
|
||||
[7]: https://www.gnome-look.org
|
||||
[8]: https://opensource.com/sites/default/files/uploads/gnome-apply_theme.png (Apply a theme)
|
Loading…
Reference in New Issue
Block a user